• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "net/base/mock_host_resolver.h"
7 
8 class ExecuteScriptApiTest : public ExtensionApiTest {
9  protected:
SetupDelayedHostResolver()10   void SetupDelayedHostResolver() {
11     // We need a.com to be a little bit slow to trigger a race condition.
12     host_resolver()->AddRuleWithLatency("a.com", "127.0.0.1", 500);
13     host_resolver()->AddRule("b.com", "127.0.0.1");
14     host_resolver()->AddRule("c.com", "127.0.0.1");
15   }
16 };
17 
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,ExecuteScriptBasic)18 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptBasic) {
19   SetupDelayedHostResolver();
20   ASSERT_TRUE(StartTestServer());
21   ASSERT_TRUE(RunExtensionTest("executescript/basic")) << message_;
22 }
23 
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,ExecuteScriptInFrame)24 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptInFrame) {
25   SetupDelayedHostResolver();
26   ASSERT_TRUE(StartTestServer());
27   ASSERT_TRUE(RunExtensionTest("executescript/in_frame")) << message_;
28 }
29 
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,ExecuteScriptPermissions)30 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptPermissions) {
31   SetupDelayedHostResolver();
32   ASSERT_TRUE(StartTestServer());
33   ASSERT_TRUE(RunExtensionTest("executescript/permissions")) << message_;
34 }
35 
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,ExecuteScriptFileAfterClose)36 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFileAfterClose) {
37   host_resolver()->AddRule("b.com", "127.0.0.1");
38   ASSERT_TRUE(StartTestServer());
39   ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_;
40 }
41 
42 // Crashy, http://crbug.com/67774.
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,DISABLED_ExecuteScriptFragmentNavigation)43 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,
44                        DISABLED_ExecuteScriptFragmentNavigation) {
45   ASSERT_TRUE(StartTestServer());
46   const char* extension_name = "executescript/fragment";
47   ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
48 }
49 
50 #if defined(OS_LINUX)
51 // Flakily times out: http://crbug.com/78802
52 #define MAYBE_NavigationRace DISABLED_NavigationRace
53 #else
54 #define MAYBE_NavigationRace NavigationRace
55 #endif
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,MAYBE_NavigationRace)56 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, MAYBE_NavigationRace) {
57   host_resolver()->AddRule("a.com", "127.0.0.1");
58   host_resolver()->AddRule("b.com", "127.0.0.1");
59   ASSERT_TRUE(StartTestServer());
60   ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race",
61                                   "execute_script.html")) << message_;
62   ASSERT_TRUE(RunExtensionSubtest("executescript/navigation_race",
63                                   "javascript_url.html")) << message_;
64 }
65 
IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest,ExecuteScriptFrameAfterLoad)66 IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFrameAfterLoad) {
67   SetupDelayedHostResolver();
68   ASSERT_TRUE(StartTestServer());
69   ASSERT_TRUE(RunExtensionTest("executescript/frame_after_load")) << message_;
70 }
71