Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_incognito_apitest.cc
blobc9a33c21f6a3abc65f1b8864e1ecd3a557f461c3
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/browser_action_test_util.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/browser_test_utils.h"
16 #include "extensions/test/extension_test_message_listener.h"
17 #include "extensions/test/result_catcher.h"
18 #include "net/dns/mock_host_resolver.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h"
21 using content::WebContents;
22 using extensions::ResultCatcher;
24 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) {
25 ASSERT_TRUE(StartEmbeddedTestServer());
27 // Loads a simple extension which attempts to change the title of every page
28 // that loads to "modified".
29 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito")
30 .AppendASCII("content_scripts")));
32 // Open incognito window and navigate to test page.
33 Browser* otr_browser = OpenURLOffTheRecord(
34 browser()->profile(),
35 embedded_test_server()->GetURL("/extensions/test_file.html"));
37 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents();
39 // Verify the script didn't run.
40 bool result = false;
41 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
42 tab,
43 "window.domAutomationController.send(document.title == 'Unmodified')",
44 &result));
45 EXPECT_TRUE(result);
48 #if defined(OS_WIN)
49 // This test is very flaky on XP. http://crbug.com/248821
50 #define MAYBE_IncognitoYesScript DISABLED_IncognitoYesScript
51 #else
52 #define MAYBE_IncognitoYesScript IncognitoYesScript
53 #endif
55 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoYesScript) {
56 host_resolver()->AddRule("*", "127.0.0.1");
57 ASSERT_TRUE(StartEmbeddedTestServer());
59 // Load a dummy extension. This just tests that we don't regress a
60 // crash fix when multiple incognito- and non-incognito-enabled extensions
61 // are mixed.
62 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts")
63 .AppendASCII("all_frames")));
65 // Loads a simple extension which attempts to change the title of every page
66 // that loads to "modified".
67 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
68 .AppendASCII("incognito").AppendASCII("content_scripts")));
70 // Dummy extension #2.
71 ASSERT_TRUE(LoadExtension(test_data_dir_
72 .AppendASCII("content_scripts").AppendASCII("isolated_world1")));
74 // Open incognito window and navigate to test page.
75 Browser* otr_browser = OpenURLOffTheRecord(
76 browser()->profile(),
77 embedded_test_server()->GetURL("/extensions/test_file.html"));
79 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents();
81 // Verify the script ran.
82 bool result = false;
83 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
84 tab,
85 "window.domAutomationController.send(document.title == 'modified')",
86 &result));
87 EXPECT_TRUE(result);
90 // Tests that an extension which is enabled for incognito mode doesn't
91 // accidentially create and incognito profile.
92 // Test disabled due to http://crbug.com/89054.
93 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_DontCreateIncognitoProfile) {
94 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
95 ASSERT_TRUE(RunExtensionTestIncognito(
96 "incognito/dont_create_profile")) << message_;
97 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
100 #if defined(OS_WIN) || defined(OS_MACOSX)
101 // http://crbug.com/120484
102 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) {
103 #else
104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) {
105 #endif
106 host_resolver()->AddRule("*", "127.0.0.1");
107 ASSERT_TRUE(StartEmbeddedTestServer());
109 ResultCatcher catcher;
111 // Open incognito window and navigate to test page.
112 OpenURLOffTheRecord(
113 browser()->profile(),
114 embedded_test_server()->GetURL("/extensions/test_file.html"));
116 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
117 .AppendASCII("incognito").AppendASCII("apis")));
119 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
122 // Tests that the APIs in an incognito-enabled split-mode extension work
123 // properly.
124 // http://crbug.com/120484
125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) {
126 host_resolver()->AddRule("*", "127.0.0.1");
127 ASSERT_TRUE(StartEmbeddedTestServer());
129 // We need 2 ResultCatchers because we'll be running the same test in both
130 // regular and incognito mode.
131 ResultCatcher catcher;
132 catcher.RestrictToBrowserContext(browser()->profile());
133 ResultCatcher catcher_incognito;
134 catcher_incognito.RestrictToBrowserContext(
135 browser()->profile()->GetOffTheRecordProfile());
137 ExtensionTestMessageListener listener("waiting", true);
138 ExtensionTestMessageListener listener_incognito("waiting_incognito", true);
140 // Open incognito window and navigate to test page.
141 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL(
142 "/extensions/test_file.html"));
144 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
145 .AppendASCII("incognito").AppendASCII("split")));
147 // Wait for both extensions to be ready before telling them to proceed.
148 EXPECT_TRUE(listener.WaitUntilSatisfied());
149 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied());
150 listener.Reply("go");
151 listener_incognito.Reply("go");
153 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
154 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
157 // Tests that the APIs in an incognito-disabled extension don't see incognito
158 // events or callbacks.
159 #if defined(OS_WIN)
160 // http://crbug.com/120484
161 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) {
162 #else
163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) {
164 #endif
165 host_resolver()->AddRule("*", "127.0.0.1");
166 ASSERT_TRUE(StartEmbeddedTestServer());
168 ResultCatcher catcher;
169 ExtensionTestMessageListener listener("createIncognitoTab", true);
171 // Open incognito window and navigate to test page.
172 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL(
173 "/extensions/test_file.html"));
175 ASSERT_TRUE(LoadExtension(test_data_dir_
176 .AppendASCII("incognito").AppendASCII("apis_disabled")));
178 EXPECT_TRUE(listener.WaitUntilSatisfied());
179 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
180 listener.Reply("created");
182 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
185 // Test that opening a popup from an incognito browser window works properly.
186 // http://crbug.com/180759.
187 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoPopup) {
188 host_resolver()->AddRule("*", "127.0.0.1");
189 ASSERT_TRUE(StartEmbeddedTestServer());
191 ResultCatcher catcher;
193 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
194 .AppendASCII("incognito").AppendASCII("popup")));
196 // Open incognito window and navigate to test page.
197 Browser* incognito_browser = OpenURLOffTheRecord(
198 browser()->profile(),
199 embedded_test_server()->GetURL("/extensions/test_file.html"));
201 // Simulate the incognito's browser action being clicked.
202 BrowserActionTestUtil(incognito_browser).Press(0);
204 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();