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

Side by Side Diff: chrome/browser/browser_browsertest.cc

Issue 2821011: Removes phantom tabs. (Closed)
Patch Set: Created 10 years, 6 months 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
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/cocoa/browser_window_controller.mm » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <string> 5 #include <string>
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 private: 87 private:
88 int closing_count_; 88 int closing_count_;
89 89
90 DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver); 90 DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver);
91 }; 91 };
92 92
93 } // namespace 93 } // namespace
94 94
95 class BrowserTest : public ExtensionBrowserTest { 95 class BrowserTest : public ExtensionBrowserTest {
96 public: 96 public:
97 // Used by phantom tab tests. Creates two tabs, pins the first and makes it
98 // a phantom tab (by closing it).
99 void PhantomTabTest() {
100 HTTPTestServer* server = StartHTTPServer();
101 ASSERT_TRUE(server);
102 host_resolver()->AddRule("www.example.com", "127.0.0.1");
103 GURL url(server->TestServerPage("empty.html"));
104 TabStripModel* model = browser()->tabstrip_model();
105
106 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/")));
107
108 Extension* extension_app = GetExtension();
109
110 ui_test_utils::NavigateToURL(browser(), url);
111
112 TabContents* app_contents = new TabContents(browser()->profile(), NULL,
113 MSG_ROUTING_NONE, NULL);
114 app_contents->SetExtensionApp(extension_app);
115
116 model->AddTabContents(app_contents, 0, false, 0, false);
117 model->SetTabPinned(0, true);
118 ui_test_utils::NavigateToURL(browser(), url);
119
120 // Close the first, which should make it a phantom.
121 model->CloseTabContentsAt(0, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB);
122
123 // There should still be two tabs.
124 ASSERT_EQ(2, browser()->tab_count());
125 // The first tab should be a phantom.
126 EXPECT_TRUE(model->IsPhantomTab(0));
127 // And the tab contents of the first tab should have changed.
128 EXPECT_TRUE(model->GetTabContentsAt(0) != app_contents);
129 }
130
131 protected: 97 protected:
132 virtual void SetUpCommandLine(CommandLine* command_line) { 98 virtual void SetUpCommandLine(CommandLine* command_line) {
133 ExtensionBrowserTest::SetUpCommandLine(command_line); 99 ExtensionBrowserTest::SetUpCommandLine(command_line);
134 100
135 // Needed for phantom tab tests. 101 // Needed for app tab tests.
136 command_line->AppendSwitch(switches::kEnableApps); 102 command_line->AppendSwitch(switches::kEnableApps);
137 } 103 }
138 104
139 // In RTL locales wrap the page title with RTL embedding characters so that it 105 // In RTL locales wrap the page title with RTL embedding characters so that it
140 // matches the value returned by GetWindowTitle(). 106 // matches the value returned by GetWindowTitle().
141 std::wstring LocaleWindowCaptionFromPageTitle( 107 std::wstring LocaleWindowCaptionFromPageTitle(
142 const std::wstring& expected_title) { 108 const std::wstring& expected_title) {
143 std::wstring page_title = WindowCaptionFromPageTitle(expected_title); 109 std::wstring page_title = WindowCaptionFromPageTitle(expected_title);
144 #if defined(OS_WIN) 110 #if defined(OS_WIN)
145 std::string locale = g_browser_process->GetApplicationLocale(); 111 std::string locale = g_browser_process->GetApplicationLocale();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 static const FilePath::CharType* kIcon = 386 static const FilePath::CharType* kIcon =
421 FILE_PATH_LITERAL("test1.png"); 387 FILE_PATH_LITERAL("test1.png");
422 GURL expected_favicon_url( 388 GURL expected_favicon_url(
423 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 389 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
424 FilePath(kIcon))); 390 FilePath(kIcon)));
425 EXPECT_EQ(expected_favicon_url.spec(), entry->favicon().url().spec()); 391 EXPECT_EQ(expected_favicon_url.spec(), entry->favicon().url().spec());
426 } 392 }
427 393
428 // TODO(sky): get these to run on a Mac. 394 // TODO(sky): get these to run on a Mac.
429 #if !defined(OS_MACOSX) 395 #if !defined(OS_MACOSX)
430 IN_PROC_BROWSER_TEST_F(BrowserTest, PhantomTab) {
431 PhantomTabTest();
432 }
433
434 IN_PROC_BROWSER_TEST_F(BrowserTest, RevivePhantomTab) {
435 PhantomTabTest();
436
437 if (HasFatalFailure())
438 return;
439
440 TabStripModel* model = browser()->tabstrip_model();
441
442 // Revive the phantom tab by selecting it.
443 browser()->SelectTabContentsAt(0, true);
444
445 // There should still be two tabs.
446 ASSERT_EQ(2, browser()->tab_count());
447 // The first tab should no longer be a phantom.
448 EXPECT_FALSE(model->IsPhantomTab(0));
449 }
450
451 // Makes sure TabClosing is sent when uninstalling an extension that is an app 396 // Makes sure TabClosing is sent when uninstalling an extension that is an app
452 // tab. 397 // tab.
453 IN_PROC_BROWSER_TEST_F(BrowserTest, TabClosingWhenRemovingExtension) { 398 IN_PROC_BROWSER_TEST_F(BrowserTest, TabClosingWhenRemovingExtension) {
454 HTTPTestServer* server = StartHTTPServer(); 399 HTTPTestServer* server = StartHTTPServer();
455 ASSERT_TRUE(server); 400 ASSERT_TRUE(server);
456 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 401 host_resolver()->AddRule("www.example.com", "127.0.0.1");
457 GURL url(server->TestServerPage("empty.html")); 402 GURL url(server->TestServerPage("empty.html"));
458 TabStripModel* model = browser()->tabstrip_model(); 403 TabStripModel* model = browser()->tabstrip_model();
459 404
460 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); 405 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/")));
(...skipping 17 matching lines...) Expand all
478 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 423 ExtensionsService* service = browser()->profile()->GetExtensionsService();
479 service->UninstallExtension(GetExtension()->id(), false); 424 service->UninstallExtension(GetExtension()->id(), false);
480 EXPECT_EQ(1, observer.closing_count()); 425 EXPECT_EQ(1, observer.closing_count());
481 426
482 model->RemoveObserver(&observer); 427 model->RemoveObserver(&observer);
483 428
484 // There should only be one tab now. 429 // There should only be one tab now.
485 ASSERT_EQ(1, browser()->tab_count()); 430 ASSERT_EQ(1, browser()->tab_count());
486 } 431 }
487 432
488 IN_PROC_BROWSER_TEST_F(BrowserTest, AppTabRemovedWhenExtensionUninstalled) {
489 PhantomTabTest();
490
491 Extension* extension = GetExtension();
492 UninstallExtension(extension->id());
493
494 // The uninstall should have removed the tab.
495 ASSERT_EQ(1, browser()->tab_count());
496 }
497 #endif // !defined(OS_MACOSX) 433 #endif // !defined(OS_MACOSX)
498 434
499 #if defined(OS_WIN) 435 #if defined(OS_WIN)
500 // http://crbug.com/46198. On XP/Vista, the failure rate is 5 ~ 6%. 436 // http://crbug.com/46198. On XP/Vista, the failure rate is 5 ~ 6%.
501 #define MAYBE_PageLanguageDetection FLAKY_PageLanguageDetection 437 #define MAYBE_PageLanguageDetection FLAKY_PageLanguageDetection
502 #else 438 #else
503 #define MAYBE_PageLanguageDetection PageLanguageDetection 439 #define MAYBE_PageLanguageDetection PageLanguageDetection
504 #endif 440 #endif
505 // Tests that the CLD (Compact Language Detection) works properly. 441 // Tests that the CLD (Compact Language Detection) works properly.
506 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) { 442 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageLanguageDetection) {
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 896
961 // The normal browser should now have four. 897 // The normal browser should now have four.
962 EXPECT_EQ(4, browser()->tab_count()); 898 EXPECT_EQ(4, browser()->tab_count());
963 899
964 // Close the additional browsers. 900 // Close the additional browsers.
965 popup_browser->CloseAllTabs(); 901 popup_browser->CloseAllTabs();
966 app_browser->CloseAllTabs(); 902 app_browser->CloseAllTabs();
967 app_popup_browser->CloseAllTabs(); 903 app_popup_browser->CloseAllTabs();
968 } 904 }
969 #endif 905 #endif
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/cocoa/browser_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698