OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
7 #include "chrome/browser/download/download_service.h" | 7 #include "chrome/browser/download/download_service.h" |
8 #include "chrome/browser/download/download_service_factory.h" | 8 #include "chrome/browser/download/download_service_factory.h" |
9 #include "chrome/browser/net/url_request_mock_util.h" | 9 #include "chrome/browser/net/url_request_mock_util.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/find_bar/find_bar.h" | 14 #include "chrome/browser/ui/find_bar/find_bar.h" |
15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
16 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 16 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
17 #include "chrome/browser/ui/panels/native_panel.h" | 17 #include "chrome/browser/ui/panels/native_panel.h" |
18 #include "chrome/browser/ui/panels/panel.h" | 18 #include "chrome/browser/ui/panels/panel.h" |
19 #include "chrome/browser/ui/panels/panel_manager.h" | 19 #include "chrome/browser/ui/panels/panel_manager.h" |
20 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 20 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
21 #include "chrome/browser/web_applications/web_app.h" | 21 #include "chrome/browser/web_applications/web_app.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
25 #include "content/browser/download/download_manager.h" | 26 #include "content/browser/download/download_manager.h" |
26 #include "content/browser/net/url_request_mock_http_job.h" | 27 #include "content/browser/net/url_request_mock_http_job.h" |
27 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/tab_contents/tab_contents.h" |
| 29 #include "content/public/browser/notification_service.h" |
28 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 | 32 |
31 class PanelBrowserTest : public BasePanelBrowserTest { | 33 class PanelBrowserTest : public BasePanelBrowserTest { |
32 public: | 34 public: |
33 PanelBrowserTest() : BasePanelBrowserTest() { | 35 PanelBrowserTest() : BasePanelBrowserTest() { |
34 } | 36 } |
35 | 37 |
36 protected: | 38 protected: |
37 void CloseWindowAndWait(Browser* browser) { | 39 void CloseWindowAndWait(Browser* browser) { |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | 1308 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
1307 | 1309 |
1308 // Another check for the same. | 1310 // Another check for the same. |
1309 EXPECT_FALSE(panel1->IsActive()); | 1311 EXPECT_FALSE(panel1->IsActive()); |
1310 EXPECT_FALSE(panel2->IsActive()); | 1312 EXPECT_FALSE(panel2->IsActive()); |
1311 | 1313 |
1312 panel1->Close(); | 1314 panel1->Close(); |
1313 panel2->Close(); | 1315 panel2->Close(); |
1314 } | 1316 } |
1315 | 1317 |
| 1318 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1319 NonExtensionDomainPanelsCloseOnUninstall) { |
| 1320 // Create a test extension. |
| 1321 DictionaryValue empty_value; |
| 1322 scoped_refptr<Extension> extension = |
| 1323 CreateExtension(FILE_PATH_LITERAL("TestExtension"), |
| 1324 Extension::INVALID, empty_value); |
| 1325 std::string extension_app_name = |
| 1326 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 1327 |
| 1328 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1329 EXPECT_EQ(0, panel_manager->num_panels()); |
| 1330 |
| 1331 // Create a panel with the extension as host. |
| 1332 CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE); |
| 1333 std::string extension_domain_url(chrome::kExtensionScheme); |
| 1334 extension_domain_url += "://"; |
| 1335 extension_domain_url += extension->id(); |
| 1336 extension_domain_url += "/hello.html"; |
| 1337 params.url = GURL(extension_domain_url); |
| 1338 Panel* panel = CreatePanelWithParams(params); |
| 1339 EXPECT_EQ(1, panel_manager->num_panels()); |
| 1340 |
| 1341 // Create a panel with a non-extension host. |
| 1342 CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE); |
| 1343 params1.url = GURL(chrome::kAboutBlankURL); |
| 1344 Panel* panel1 = CreatePanelWithParams(params1); |
| 1345 EXPECT_EQ(2, panel_manager->num_panels()); |
| 1346 |
| 1347 // Create another extension and a panel from that extension. |
| 1348 scoped_refptr<Extension> extension_other = |
| 1349 CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"), |
| 1350 Extension::INVALID, empty_value); |
| 1351 std::string extension_app_name_other = |
| 1352 web_app::GenerateApplicationNameFromExtensionId(extension_other->id()); |
| 1353 Panel* panel_other = CreatePanel(extension_app_name_other); |
| 1354 |
| 1355 ui_test_utils::WindowedNotificationObserver signal( |
| 1356 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1357 content::Source<Browser>(panel->browser())); |
| 1358 ui_test_utils::WindowedNotificationObserver signal1( |
| 1359 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1360 content::Source<Browser>(panel1->browser())); |
| 1361 |
| 1362 // Send unload notification on the first extension. |
| 1363 UnloadedExtensionInfo details(extension, |
| 1364 extension_misc::UNLOAD_REASON_UNINSTALL); |
| 1365 content::NotificationService::current()->Notify( |
| 1366 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 1367 content::Source<Profile>(browser()->profile()), |
| 1368 content::Details<UnloadedExtensionInfo>(&details)); |
| 1369 |
| 1370 // Wait for the panels opened by the first extension to close. |
| 1371 signal.Wait(); |
| 1372 signal1.Wait(); |
| 1373 |
| 1374 // Verify that the panel that's left is the panel from the second extension. |
| 1375 EXPECT_EQ(panel_other, panel_manager->panels()[0]); |
| 1376 panel_other->Close(); |
| 1377 } |
| 1378 |
1316 class PanelDownloadTest : public PanelBrowserTest { | 1379 class PanelDownloadTest : public PanelBrowserTest { |
1317 public: | 1380 public: |
1318 PanelDownloadTest() : PanelBrowserTest() { } | 1381 PanelDownloadTest() : PanelBrowserTest() { } |
1319 | 1382 |
1320 // Creates a temporary directory for downloads that is auto-deleted | 1383 // Creates a temporary directory for downloads that is auto-deleted |
1321 // on destruction. | 1384 // on destruction. |
1322 bool CreateDownloadDirectory(Profile* profile) { | 1385 bool CreateDownloadDirectory(Profile* profile) { |
1323 bool created = downloads_directory_.CreateUniqueTempDir(); | 1386 bool created = downloads_directory_.CreateUniqueTempDir(); |
1324 if (!created) | 1387 if (!created) |
1325 return false; | 1388 return false; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 EXPECT_EQ(1, tabbed_browser->tab_count()); | 1543 EXPECT_EQ(1, tabbed_browser->tab_count()); |
1481 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 1544 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
1482 tabbed_browser->CloseWindow(); | 1545 tabbed_browser->CloseWindow(); |
1483 #endif | 1546 #endif |
1484 | 1547 |
1485 EXPECT_EQ(1, panel_browser->tab_count()); | 1548 EXPECT_EQ(1, panel_browser->tab_count()); |
1486 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 1549 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
1487 | 1550 |
1488 panel_browser->CloseWindow(); | 1551 panel_browser->CloseWindow(); |
1489 } | 1552 } |
OLD | NEW |