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_list.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "net/base/mock_host_resolver.h" | 17 #include "net/base/mock_host_resolver.h" |
18 | 18 |
19 using content::WebContents; | 19 using content::WebContents; |
20 | 20 |
21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { | 21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { |
22 ASSERT_TRUE(StartTestServer()); | 22 ASSERT_TRUE(StartTestServer()); |
23 | 23 |
24 // Loads a simple extension which attempts to change the title of every page | 24 // Loads a simple extension which attempts to change the title of every page |
25 // that loads to "modified". | 25 // that loads to "modified". |
26 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") | 26 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") |
27 .AppendASCII("content_scripts"))); | 27 .AppendASCII("content_scripts"))); |
28 | 28 |
29 // Open incognito window and navigate to test page. | 29 // Open incognito window and navigate to test page. |
30 ui_test_utils::OpenURLOffTheRecord( | 30 ui_test_utils::OpenURLOffTheRecord( |
31 browser()->profile(), | 31 browser()->profile(), |
32 test_server()->GetURL("files/extensions/test_file.html")); | 32 test_server()->GetURL("files/extensions/test_file.html")); |
33 | 33 |
34 Browser* otr_browser = BrowserList::FindTabbedBrowser( | 34 Browser* otr_browser = browser::FindTabbedBrowser( |
35 browser()->profile()->GetOffTheRecordProfile(), false); | 35 browser()->profile()->GetOffTheRecordProfile(), false); |
36 WebContents* tab = otr_browser->GetSelectedWebContents(); | 36 WebContents* tab = otr_browser->GetSelectedWebContents(); |
37 | 37 |
38 // Verify the script didn't run. | 38 // Verify the script didn't run. |
39 bool result = false; | 39 bool result = false; |
40 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 40 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
41 tab->GetRenderViewHost(), L"", | 41 tab->GetRenderViewHost(), L"", |
42 L"window.domAutomationController.send(document.title == 'Unmodified')", | 42 L"window.domAutomationController.send(document.title == 'Unmodified')", |
43 &result)); | 43 &result)); |
44 EXPECT_TRUE(result); | 44 EXPECT_TRUE(result); |
(...skipping 16 matching lines...) Expand all Loading... |
61 | 61 |
62 // Dummy extension #2. | 62 // Dummy extension #2. |
63 ASSERT_TRUE(LoadExtension(test_data_dir_ | 63 ASSERT_TRUE(LoadExtension(test_data_dir_ |
64 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); | 64 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); |
65 | 65 |
66 // Open incognito window and navigate to test page. | 66 // Open incognito window and navigate to test page. |
67 ui_test_utils::OpenURLOffTheRecord( | 67 ui_test_utils::OpenURLOffTheRecord( |
68 browser()->profile(), | 68 browser()->profile(), |
69 test_server()->GetURL("files/extensions/test_file.html")); | 69 test_server()->GetURL("files/extensions/test_file.html")); |
70 | 70 |
71 Browser* otr_browser = BrowserList::FindTabbedBrowser( | 71 Browser* otr_browser = browser::FindTabbedBrowser( |
72 browser()->profile()->GetOffTheRecordProfile(), false); | 72 browser()->profile()->GetOffTheRecordProfile(), false); |
73 WebContents* tab = otr_browser->GetSelectedWebContents(); | 73 WebContents* tab = otr_browser->GetSelectedWebContents(); |
74 | 74 |
75 // Verify the script ran. | 75 // Verify the script ran. |
76 bool result = false; | 76 bool result = false; |
77 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 77 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
78 tab->GetRenderViewHost(), L"", | 78 tab->GetRenderViewHost(), L"", |
79 L"window.domAutomationController.send(document.title == 'modified')", | 79 L"window.domAutomationController.send(document.title == 'modified')", |
80 &result)); | 80 &result)); |
81 EXPECT_TRUE(result); | 81 EXPECT_TRUE(result); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 ResultCatcher catcher; | 191 ResultCatcher catcher; |
192 | 192 |
193 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 193 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
194 .AppendASCII("incognito").AppendASCII("popup"))); | 194 .AppendASCII("incognito").AppendASCII("popup"))); |
195 | 195 |
196 // Open incognito window and navigate to test page. | 196 // Open incognito window and navigate to test page. |
197 ui_test_utils::OpenURLOffTheRecord( | 197 ui_test_utils::OpenURLOffTheRecord( |
198 browser()->profile(), | 198 browser()->profile(), |
199 test_server()->GetURL("files/extensions/test_file.html")); | 199 test_server()->GetURL("files/extensions/test_file.html")); |
200 | 200 |
201 Browser* incognito_browser = BrowserList::FindTabbedBrowser( | 201 Browser* incognito_browser = browser::FindTabbedBrowser( |
202 browser()->profile()->GetOffTheRecordProfile(), false); | 202 browser()->profile()->GetOffTheRecordProfile(), false); |
203 | 203 |
204 // Simulate the incognito's browser action being clicked. | 204 // Simulate the incognito's browser action being clicked. |
205 BrowserActionTestUtil(incognito_browser).Press(0); | 205 BrowserActionTestUtil(incognito_browser).Press(0); |
206 | 206 |
207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
208 } | 208 } |
OLD | NEW |