OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/extensions/extension_message_bubble_browsertest.h" | 5 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 void ExtensionMessageBubbleBrowserTest::TestBubbleAnchoredToExtensionAction() { | 103 void ExtensionMessageBubbleBrowserTest::TestBubbleAnchoredToExtensionAction() { |
104 scoped_refptr<const extensions::Extension> action_extension = | 104 scoped_refptr<const extensions::Extension> action_extension = |
105 extensions::extension_action_test_util::CreateActionExtension( | 105 extensions::extension_action_test_util::CreateActionExtension( |
106 "action_extension", | 106 "action_extension", |
107 extensions::extension_action_test_util::BROWSER_ACTION, | 107 extensions::extension_action_test_util::BROWSER_ACTION, |
108 extensions::Manifest::UNPACKED); | 108 extensions::Manifest::UNPACKED); |
109 extension_service()->AddExtension(action_extension.get()); | 109 extension_service()->AddExtension(action_extension.get()); |
110 | 110 |
111 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 111 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
112 ASSERT_TRUE(second_browser); | 112 ASSERT_TRUE(second_browser); |
113 second_browser->window()->Show(); | 113 second_browser->window()->Show(); |
114 base::RunLoop().RunUntilIdle(); | 114 base::RunLoop().RunUntilIdle(); |
115 | 115 |
116 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); | 116 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); |
117 CloseBubble(second_browser); | 117 CloseBubble(second_browser); |
118 } | 118 } |
119 | 119 |
120 void ExtensionMessageBubbleBrowserTest::TestBubbleAnchoredToAppMenu() { | 120 void ExtensionMessageBubbleBrowserTest::TestBubbleAnchoredToAppMenu() { |
121 scoped_refptr<const extensions::Extension> no_action_extension = | 121 scoped_refptr<const extensions::Extension> no_action_extension = |
122 extensions::extension_action_test_util::CreateActionExtension( | 122 extensions::extension_action_test_util::CreateActionExtension( |
123 "no_action_extension", | 123 "no_action_extension", |
124 extensions::extension_action_test_util::NO_ACTION, | 124 extensions::extension_action_test_util::NO_ACTION, |
125 extensions::Manifest::UNPACKED); | 125 extensions::Manifest::UNPACKED); |
126 extension_service()->AddExtension(no_action_extension.get()); | 126 extension_service()->AddExtension(no_action_extension.get()); |
127 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 127 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
128 ASSERT_TRUE(second_browser); | 128 ASSERT_TRUE(second_browser); |
129 second_browser->window()->Show(); | 129 second_browser->window()->Show(); |
130 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
131 CheckBubble(second_browser, ANCHOR_APP_MENU, false); | 131 CheckBubble(second_browser, ANCHOR_APP_MENU, false); |
132 CloseBubble(second_browser); | 132 CloseBubble(second_browser); |
133 } | 133 } |
134 | 134 |
135 void ExtensionMessageBubbleBrowserTest:: | 135 void ExtensionMessageBubbleBrowserTest:: |
136 TestBubbleAnchoredToAppMenuWithOtherAction() { | 136 TestBubbleAnchoredToAppMenuWithOtherAction() { |
137 scoped_refptr<const extensions::Extension> no_action_extension = | 137 scoped_refptr<const extensions::Extension> no_action_extension = |
138 extensions::extension_action_test_util::CreateActionExtension( | 138 extensions::extension_action_test_util::CreateActionExtension( |
139 "no_action_extension", | 139 "no_action_extension", |
140 extensions::extension_action_test_util::NO_ACTION, | 140 extensions::extension_action_test_util::NO_ACTION, |
141 extensions::Manifest::UNPACKED); | 141 extensions::Manifest::UNPACKED); |
142 extension_service()->AddExtension(no_action_extension.get()); | 142 extension_service()->AddExtension(no_action_extension.get()); |
143 | 143 |
144 scoped_refptr<const extensions::Extension> action_extension = | 144 scoped_refptr<const extensions::Extension> action_extension = |
145 extensions::extension_action_test_util::CreateActionExtension( | 145 extensions::extension_action_test_util::CreateActionExtension( |
146 "action_extension", | 146 "action_extension", |
147 extensions::extension_action_test_util::BROWSER_ACTION, | 147 extensions::extension_action_test_util::BROWSER_ACTION, |
148 extensions::Manifest::INTERNAL); | 148 extensions::Manifest::INTERNAL); |
149 extension_service()->AddExtension(action_extension.get()); | 149 extension_service()->AddExtension(action_extension.get()); |
150 | 150 |
151 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 151 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
152 ASSERT_TRUE(second_browser); | 152 ASSERT_TRUE(second_browser); |
153 second_browser->window()->Show(); | 153 second_browser->window()->Show(); |
154 base::RunLoop().RunUntilIdle(); | 154 base::RunLoop().RunUntilIdle(); |
155 | 155 |
156 CheckBubble(second_browser, ANCHOR_APP_MENU, false); | 156 CheckBubble(second_browser, ANCHOR_APP_MENU, false); |
157 CloseBubble(second_browser); | 157 CloseBubble(second_browser); |
158 } | 158 } |
159 | 159 |
160 void ExtensionMessageBubbleBrowserTest::TestUninstallDangerousExtension() { | 160 void ExtensionMessageBubbleBrowserTest::TestUninstallDangerousExtension() { |
161 // Load an extension that overrides the proxy setting. | 161 // Load an extension that overrides the proxy setting. |
162 ExtensionTestMessageListener listener("registered", false); | 162 ExtensionTestMessageListener listener("registered", false); |
163 const extensions::Extension* extension = | 163 const extensions::Extension* extension = |
164 LoadExtension(test_data_dir_.AppendASCII("api_test") | 164 LoadExtension(test_data_dir_.AppendASCII("api_test") |
165 .AppendASCII("proxy") | 165 .AppendASCII("proxy") |
166 .AppendASCII("register")); | 166 .AppendASCII("register")); |
167 // Wait for it to complete. | 167 // Wait for it to complete. |
168 listener.WaitUntilSatisfied(); | 168 listener.WaitUntilSatisfied(); |
169 | 169 |
170 // Create a second browser with the extension installed - the bubble will be | 170 // Create a second browser with the extension installed - the bubble will be |
171 // set to show. | 171 // set to show. |
172 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 172 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
173 ASSERT_TRUE(second_browser); | 173 ASSERT_TRUE(second_browser); |
174 second_browser->window()->Show(); | 174 second_browser->window()->Show(); |
175 // Uninstall the extension before the bubble is shown. This should not crash, | 175 // Uninstall the extension before the bubble is shown. This should not crash, |
176 // and the bubble shouldn't be shown. | 176 // and the bubble shouldn't be shown. |
177 extension_service()->UninstallExtension( | 177 extension_service()->UninstallExtension( |
178 extension->id(), extensions::UNINSTALL_REASON_FOR_TESTING, | 178 extension->id(), extensions::UNINSTALL_REASON_FOR_TESTING, |
179 base::Bind(&base::DoNothing), nullptr); | 179 base::Bind(&base::DoNothing), nullptr); |
180 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
181 CheckBubbleIsNotPresent(second_browser, false, false); | 181 CheckBubbleIsNotPresent(second_browser, false, false); |
182 } | 182 } |
183 | 183 |
184 void ExtensionMessageBubbleBrowserTest::PreBubbleShowsOnStartup() { | 184 void ExtensionMessageBubbleBrowserTest::PreBubbleShowsOnStartup() { |
185 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); | 185 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); |
186 } | 186 } |
187 | 187 |
188 void ExtensionMessageBubbleBrowserTest::TestBubbleShowsOnStartup() { | 188 void ExtensionMessageBubbleBrowserTest::TestBubbleShowsOnStartup() { |
189 base::RunLoop().RunUntilIdle(); | 189 base::RunLoop().RunUntilIdle(); |
190 CheckBubble(browser(), ANCHOR_BROWSER_ACTION, true); | 190 CheckBubble(browser(), ANCHOR_BROWSER_ACTION, true); |
191 CloseBubble(browser()); | 191 CloseBubble(browser()); |
192 } | 192 } |
193 | 193 |
194 void ExtensionMessageBubbleBrowserTest::TestDevModeBubbleIsntShownTwice() { | 194 void ExtensionMessageBubbleBrowserTest::TestDevModeBubbleIsntShownTwice() { |
195 scoped_refptr<const extensions::Extension> action_extension = | 195 scoped_refptr<const extensions::Extension> action_extension = |
196 extensions::extension_action_test_util::CreateActionExtension( | 196 extensions::extension_action_test_util::CreateActionExtension( |
197 "action_extension", | 197 "action_extension", |
198 extensions::extension_action_test_util::BROWSER_ACTION, | 198 extensions::extension_action_test_util::BROWSER_ACTION, |
199 extensions::Manifest::UNPACKED); | 199 extensions::Manifest::UNPACKED); |
200 extension_service()->AddExtension(action_extension.get()); | 200 extension_service()->AddExtension(action_extension.get()); |
201 | 201 |
202 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 202 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
203 ASSERT_TRUE(second_browser); | 203 ASSERT_TRUE(second_browser); |
204 second_browser->window()->Show(); | 204 second_browser->window()->Show(); |
205 base::RunLoop().RunUntilIdle(); | 205 base::RunLoop().RunUntilIdle(); |
206 | 206 |
207 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); | 207 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); |
208 CloseBubble(second_browser); | 208 CloseBubble(second_browser); |
209 base::RunLoop().RunUntilIdle(); | 209 base::RunLoop().RunUntilIdle(); |
210 | 210 |
211 // The bubble was already shown, so it shouldn't be shown again. | 211 // The bubble was already shown, so it shouldn't be shown again. |
212 Browser* third_browser = new Browser(Browser::CreateParams(profile())); | 212 Browser* third_browser = new Browser(Browser::CreateParams(profile(), true)); |
213 ASSERT_TRUE(third_browser); | 213 ASSERT_TRUE(third_browser); |
214 third_browser->window()->Show(); | 214 third_browser->window()->Show(); |
215 base::RunLoop().RunUntilIdle(); | 215 base::RunLoop().RunUntilIdle(); |
216 CheckBubbleIsNotPresent(third_browser, false, false); | 216 CheckBubbleIsNotPresent(third_browser, false, false); |
217 } | 217 } |
218 | 218 |
219 void ExtensionMessageBubbleBrowserTest::TestControlledNewTabPageBubbleShown() { | 219 void ExtensionMessageBubbleBrowserTest::TestControlledNewTabPageBubbleShown() { |
220 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") | 220 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") |
221 .AppendASCII("override") | 221 .AppendASCII("override") |
222 .AppendASCII("newtab"))); | 222 .AppendASCII("newtab"))); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 290 |
291 void ExtensionMessageBubbleBrowserTest:: | 291 void ExtensionMessageBubbleBrowserTest:: |
292 TestControlledStartupNotShownOnRestart() { | 292 TestControlledStartupNotShownOnRestart() { |
293 EXPECT_TRUE(StartupBrowserCreator::WasRestarted()); | 293 EXPECT_TRUE(StartupBrowserCreator::WasRestarted()); |
294 CheckBubbleIsNotPresent(browser(), false, false); | 294 CheckBubbleIsNotPresent(browser(), false, false); |
295 } | 295 } |
296 | 296 |
297 void ExtensionMessageBubbleBrowserTest::TestBubbleWithMultipleWindows() { | 297 void ExtensionMessageBubbleBrowserTest::TestBubbleWithMultipleWindows() { |
298 CheckBubbleIsNotPresent(browser(), false, false); | 298 CheckBubbleIsNotPresent(browser(), false, false); |
299 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); | 299 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); |
300 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 300 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
301 ASSERT_TRUE(second_browser); | 301 ASSERT_TRUE(second_browser); |
302 second_browser->window()->Show(); | 302 second_browser->window()->Show(); |
303 Browser* third_browser = new Browser(Browser::CreateParams(profile())); | 303 Browser* third_browser = new Browser(Browser::CreateParams(profile(), true)); |
304 ASSERT_TRUE(third_browser); | 304 ASSERT_TRUE(third_browser); |
305 third_browser->window()->Show(); | 305 third_browser->window()->Show(); |
306 Browser* fourth_browser = new Browser(Browser::CreateParams(profile())); | 306 Browser* fourth_browser = new Browser(Browser::CreateParams(profile(), true)); |
307 ASSERT_TRUE(fourth_browser); | 307 ASSERT_TRUE(fourth_browser); |
308 fourth_browser->window()->Show(); | 308 fourth_browser->window()->Show(); |
309 base::RunLoop().RunUntilIdle(); | 309 base::RunLoop().RunUntilIdle(); |
310 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); | 310 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); |
311 // Even though the bubble isn't present on these browser windows, highlighting | 311 // Even though the bubble isn't present on these browser windows, highlighting |
312 // is per-profile. | 312 // is per-profile. |
313 CheckBubbleIsNotPresent(browser(), true, true); | 313 CheckBubbleIsNotPresent(browser(), true, true); |
314 CheckBubbleIsNotPresent(third_browser, true, true); | 314 CheckBubbleIsNotPresent(third_browser, true, true); |
315 CheckBubbleIsNotPresent(fourth_browser, true, true); | 315 CheckBubbleIsNotPresent(fourth_browser, true, true); |
316 CloseBubble(second_browser); | 316 CloseBubble(second_browser); |
317 } | 317 } |
318 | 318 |
319 void ExtensionMessageBubbleBrowserTest::TestClickingLearnMoreButton() { | 319 void ExtensionMessageBubbleBrowserTest::TestClickingLearnMoreButton() { |
320 CheckBubbleIsNotPresent(browser(), false, false); | 320 CheckBubbleIsNotPresent(browser(), false, false); |
321 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); | 321 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); |
322 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 322 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
323 ASSERT_TRUE(second_browser); | 323 ASSERT_TRUE(second_browser); |
324 second_browser->window()->Show(); | 324 second_browser->window()->Show(); |
325 base::RunLoop().RunUntilIdle(); | 325 base::RunLoop().RunUntilIdle(); |
326 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); | 326 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); |
327 ClickLearnMoreButton(second_browser); | 327 ClickLearnMoreButton(second_browser); |
328 base::RunLoop().RunUntilIdle(); | 328 base::RunLoop().RunUntilIdle(); |
329 CheckBubbleIsNotPresent(second_browser, false, false); | 329 CheckBubbleIsNotPresent(second_browser, false, false); |
330 // The learn more link goes to the chrome://extensions page, so it should be | 330 // The learn more link goes to the chrome://extensions page, so it should be |
331 // opened in the active tab. | 331 // opened in the active tab. |
332 content::WebContents* active_web_contents = | 332 content::WebContents* active_web_contents = |
333 second_browser->tab_strip_model()->GetActiveWebContents(); | 333 second_browser->tab_strip_model()->GetActiveWebContents(); |
334 content::WaitForLoadStop(active_web_contents); | 334 content::WaitForLoadStop(active_web_contents); |
335 EXPECT_EQ(GURL(chrome::kChromeUIExtensionsURL), | 335 EXPECT_EQ(GURL(chrome::kChromeUIExtensionsURL), |
336 active_web_contents->GetLastCommittedURL()); | 336 active_web_contents->GetLastCommittedURL()); |
337 } | 337 } |
338 | 338 |
339 void ExtensionMessageBubbleBrowserTest::TestClickingActionButton() { | 339 void ExtensionMessageBubbleBrowserTest::TestClickingActionButton() { |
340 CheckBubbleIsNotPresent(browser(), false, false); | 340 CheckBubbleIsNotPresent(browser(), false, false); |
341 const extensions::Extension* extension = | 341 const extensions::Extension* extension = |
342 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); | 342 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); |
343 extensions::ExtensionRegistry* registry = | 343 extensions::ExtensionRegistry* registry = |
344 extensions::ExtensionRegistry::Get(profile()); | 344 extensions::ExtensionRegistry::Get(profile()); |
345 std::string id = extension->id(); | 345 std::string id = extension->id(); |
346 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); | 346 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); |
347 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 347 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
348 ASSERT_TRUE(second_browser); | 348 ASSERT_TRUE(second_browser); |
349 second_browser->window()->Show(); | 349 second_browser->window()->Show(); |
350 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
351 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); | 351 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); |
352 ClickActionButton(second_browser); | 352 ClickActionButton(second_browser); |
353 base::RunLoop().RunUntilIdle(); | 353 base::RunLoop().RunUntilIdle(); |
354 CheckBubbleIsNotPresent(browser(), false, false); | 354 CheckBubbleIsNotPresent(browser(), false, false); |
355 // Clicking the action button disabled the extension. | 355 // Clicking the action button disabled the extension. |
356 EXPECT_FALSE(registry->enabled_extensions().GetByID(id)); | 356 EXPECT_FALSE(registry->enabled_extensions().GetByID(id)); |
357 } | 357 } |
358 | 358 |
359 void ExtensionMessageBubbleBrowserTest::TestClickingDismissButton() { | 359 void ExtensionMessageBubbleBrowserTest::TestClickingDismissButton() { |
360 CheckBubbleIsNotPresent(browser(), false, false); | 360 CheckBubbleIsNotPresent(browser(), false, false); |
361 const extensions::Extension* extension = | 361 const extensions::Extension* extension = |
362 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); | 362 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); |
363 extensions::ExtensionRegistry* registry = | 363 extensions::ExtensionRegistry* registry = |
364 extensions::ExtensionRegistry::Get(profile()); | 364 extensions::ExtensionRegistry::Get(profile()); |
365 std::string id = extension->id(); | 365 std::string id = extension->id(); |
366 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); | 366 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); |
367 Browser* second_browser = new Browser(Browser::CreateParams(profile())); | 367 Browser* second_browser = new Browser(Browser::CreateParams(profile(), true)); |
368 ASSERT_TRUE(second_browser); | 368 ASSERT_TRUE(second_browser); |
369 second_browser->window()->Show(); | 369 second_browser->window()->Show(); |
370 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
371 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); | 371 CheckBubble(second_browser, ANCHOR_BROWSER_ACTION, true); |
372 ClickDismissButton(second_browser); | 372 ClickDismissButton(second_browser); |
373 base::RunLoop().RunUntilIdle(); | 373 base::RunLoop().RunUntilIdle(); |
374 CheckBubbleIsNotPresent(browser(), false, false); | 374 CheckBubbleIsNotPresent(browser(), false, false); |
375 // Clicking dismiss should have no affect, so the extension should still be | 375 // Clicking dismiss should have no affect, so the extension should still be |
376 // active. | 376 // active. |
377 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); | 377 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); |
378 } | 378 } |
OLD | NEW |