OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/browser_action_test_util.h" | 5 #include "chrome/browser/extensions/browser_action_test_util.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/extension_test_message_listener.h" | 8 #include "chrome/browser/extensions/extension_test_message_listener.h" |
9 #include "chrome/browser/extensions/user_script_master.h" | 9 #include "chrome/browser/extensions/user_script_master.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" |
13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "net/base/mock_host_resolver.h" | 18 #include "net/base/mock_host_resolver.h" |
18 | 19 |
19 using content::WebContents; | 20 using content::WebContents; |
20 | 21 |
21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { | 22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { |
22 ASSERT_TRUE(StartTestServer()); | 23 ASSERT_TRUE(StartTestServer()); |
23 | 24 |
24 // Loads a simple extension which attempts to change the title of every page | 25 // Loads a simple extension which attempts to change the title of every page |
25 // that loads to "modified". | 26 // that loads to "modified". |
26 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") | 27 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") |
27 .AppendASCII("content_scripts"))); | 28 .AppendASCII("content_scripts"))); |
28 | 29 |
29 // Open incognito window and navigate to test page. | 30 // Open incognito window and navigate to test page. |
30 ui_test_utils::OpenURLOffTheRecord( | 31 ui_test_utils::OpenURLOffTheRecord( |
31 browser()->profile(), | 32 browser()->profile(), |
32 test_server()->GetURL("files/extensions/test_file.html")); | 33 test_server()->GetURL("files/extensions/test_file.html")); |
33 | 34 |
34 Browser* otr_browser = browser::FindTabbedBrowser( | 35 Browser* otr_browser = browser::FindTabbedBrowser( |
35 browser()->profile()->GetOffTheRecordProfile(), false); | 36 browser()->profile()->GetOffTheRecordProfile(), false); |
36 WebContents* tab = otr_browser->GetActiveWebContents(); | 37 WebContents* tab = chrome::GetActiveWebContents(otr_browser); |
37 | 38 |
38 // Verify the script didn't run. | 39 // Verify the script didn't run. |
39 bool result = false; | 40 bool result = false; |
40 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 41 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
41 tab->GetRenderViewHost(), L"", | 42 tab->GetRenderViewHost(), L"", |
42 L"window.domAutomationController.send(document.title == 'Unmodified')", | 43 L"window.domAutomationController.send(document.title == 'Unmodified')", |
43 &result)); | 44 &result)); |
44 EXPECT_TRUE(result); | 45 EXPECT_TRUE(result); |
45 } | 46 } |
46 | 47 |
(...skipping 16 matching lines...) Expand all Loading... |
63 ASSERT_TRUE(LoadExtension(test_data_dir_ | 64 ASSERT_TRUE(LoadExtension(test_data_dir_ |
64 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); | 65 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); |
65 | 66 |
66 // Open incognito window and navigate to test page. | 67 // Open incognito window and navigate to test page. |
67 ui_test_utils::OpenURLOffTheRecord( | 68 ui_test_utils::OpenURLOffTheRecord( |
68 browser()->profile(), | 69 browser()->profile(), |
69 test_server()->GetURL("files/extensions/test_file.html")); | 70 test_server()->GetURL("files/extensions/test_file.html")); |
70 | 71 |
71 Browser* otr_browser = browser::FindTabbedBrowser( | 72 Browser* otr_browser = browser::FindTabbedBrowser( |
72 browser()->profile()->GetOffTheRecordProfile(), false); | 73 browser()->profile()->GetOffTheRecordProfile(), false); |
73 WebContents* tab = otr_browser->GetActiveWebContents(); | 74 WebContents* tab = chrome::GetActiveWebContents(otr_browser); |
74 | 75 |
75 // Verify the script ran. | 76 // Verify the script ran. |
76 bool result = false; | 77 bool result = false; |
77 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 78 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
78 tab->GetRenderViewHost(), L"", | 79 tab->GetRenderViewHost(), L"", |
79 L"window.domAutomationController.send(document.title == 'modified')", | 80 L"window.domAutomationController.send(document.title == 'modified')", |
80 &result)); | 81 &result)); |
81 EXPECT_TRUE(result); | 82 EXPECT_TRUE(result); |
82 } | 83 } |
83 | 84 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 test_server()->GetURL("files/extensions/test_file.html")); | 200 test_server()->GetURL("files/extensions/test_file.html")); |
200 | 201 |
201 Browser* incognito_browser = browser::FindTabbedBrowser( | 202 Browser* incognito_browser = browser::FindTabbedBrowser( |
202 browser()->profile()->GetOffTheRecordProfile(), false); | 203 browser()->profile()->GetOffTheRecordProfile(), false); |
203 | 204 |
204 // Simulate the incognito's browser action being clicked. | 205 // Simulate the incognito's browser action being clicked. |
205 BrowserActionTestUtil(incognito_browser).Press(0); | 206 BrowserActionTestUtil(incognito_browser).Press(0); |
206 | 207 |
207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 208 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
208 } | 209 } |
OLD | NEW |