Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/ui/panels/panel_browsertest.cc

Issue 8387010: Close all panels originated by the extension when extension unloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace RunAllPending in loop with waiting for notifications. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« chrome/browser/ui/browser.cc ('K') | « chrome/browser/ui/browser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
jennb 2011/10/25 17:37:47 Could you make the test load a real extension that
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);
dcheng 2011/10/25 18:06:19 Space.
prasadt 2011/10/28 18:23:19 Done.
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
1356 ui_test_utils::WindowedNotificationObserver signal(
1357 chrome::NOTIFICATION_BROWSER_CLOSED,
1358 content::Source<Browser>(panel->browser()));
1359 ui_test_utils::WindowedNotificationObserver signal1(
1360 chrome::NOTIFICATION_BROWSER_CLOSED,
1361 content::Source<Browser>(panel1->browser()));
1362
1363 // Send unload notification on the first extension.
1364 UnloadedExtensionInfo details(extension,
1365 extension_misc::UNLOAD_REASON_UNINSTALL);
1366 content::NotificationService::current()->Notify(
1367 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1368 content::Source<Profile>(browser()->profile()),
1369 content::Details<UnloadedExtensionInfo>(&details));
1370
1371 // Wait for the panels opened by the first extension to close.
1372 signal.Wait();
1373 signal1.Wait();
1374
1375 // Verify that the panel that's left is the panel from the second extension.
1376 EXPECT_EQ(panel_other, panel_manager->panels()[0]);
1377 panel_other->Close();
1378 }
1379
1316 class PanelDownloadTest : public PanelBrowserTest { 1380 class PanelDownloadTest : public PanelBrowserTest {
1317 public: 1381 public:
1318 PanelDownloadTest() : PanelBrowserTest() { } 1382 PanelDownloadTest() : PanelBrowserTest() { }
1319 1383
1320 // Creates a temporary directory for downloads that is auto-deleted 1384 // Creates a temporary directory for downloads that is auto-deleted
1321 // on destruction. 1385 // on destruction.
1322 bool CreateDownloadDirectory(Profile* profile) { 1386 bool CreateDownloadDirectory(Profile* profile) {
1323 bool created = downloads_directory_.CreateUniqueTempDir(); 1387 bool created = downloads_directory_.CreateUniqueTempDir();
1324 if (!created) 1388 if (!created)
1325 return false; 1389 return false;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 EXPECT_EQ(1, tabbed_browser->tab_count()); 1544 EXPECT_EQ(1, tabbed_browser->tab_count());
1481 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); 1545 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible());
1482 tabbed_browser->CloseWindow(); 1546 tabbed_browser->CloseWindow();
1483 #endif 1547 #endif
1484 1548
1485 EXPECT_EQ(1, panel_browser->tab_count()); 1549 EXPECT_EQ(1, panel_browser->tab_count());
1486 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); 1550 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
1487 1551
1488 panel_browser->CloseWindow(); 1552 panel_browser->CloseWindow();
1489 } 1553 }
OLDNEW
« chrome/browser/ui/browser.cc ('K') | « chrome/browser/ui/browser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698