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

Unified Diff: chrome/browser/ui/browser_tabrestore_browsertest.cc

Issue 227043004: Restored tabs should set their initial visibility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DOMMessageQueue simplifications. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser_tabrestore.cc ('k') | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/browser_tabrestore_browsertest.cc
diff --git a/chrome/browser/ui/browser_tabrestore_browsertest.cc b/chrome/browser/ui/browser_tabrestore_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d41ffdc89eab0bc4dee5023c66f4ad5ecda8091d
--- /dev/null
+++ b/chrome/browser/ui/browser_tabrestore_browsertest.cc
@@ -0,0 +1,140 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
+#include "chrome/browser/sessions/tab_restore_service_delegate.h"
+#include "chrome/browser/sessions/tab_restore_service_factory.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/interactive_test_utils.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/browser_test_utils.h"
+
+typedef InProcessBrowserTest BrowserTabRestoreTest;
+
+void AwaitTabsReady(content::DOMMessageQueue* message_queue, int tabs) {
+ for (int i = 0; i < tabs; ++i) {
+ std::string message;
+ EXPECT_TRUE(message_queue->WaitForMessage(&message));
+ EXPECT_EQ("\"READY\"", message);
+ }
+}
+
+void CheckVisbility(TabStripModel* tab_strip_model, int visible_index) {
+ for (int i = 0; i < tab_strip_model->count(); ++i) {
+ content::WebContents* contents = tab_strip_model->GetWebContentsAt(i);
+ std::string document_visibility_state;
+ const char kGetStateJS[] = "window.domAutomationController.send("
+ "window.document.visibilityState);";
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ contents, kGetStateJS, &document_visibility_state));
+ if (i == visible_index) {
+ EXPECT_EQ("visible", document_visibility_state);
+ } else {
+ EXPECT_EQ("hidden", document_visibility_state);
+ }
+ }
+}
+
+void CreateTestTabs(Browser* browser) {
+ GURL test_page(ui_test_utils::GetTestUrl(base::FilePath(),
+ base::FilePath(FILE_PATH_LITERAL("tab-restore-visibilty.html"))));
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser, test_page, NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser, test_page, NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+}
+
+void CloseBrowser(Browser* browser) {
+ content::WindowedNotificationObserver close_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser));
+ chrome::CloseWindow(browser);
+ close_observer.Wait();
+}
+
+IN_PROC_BROWSER_TEST_F(BrowserTabRestoreTest, RecentTabsMenuTabDisposition) {
+ // Create tabs.
+ CreateTestTabs(browser());
+ EXPECT_EQ(3, browser()->tab_strip_model()->count());
+
+ // Create a new browser.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), GURL(), NEW_WINDOW,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
+ BrowserList* active_browser_list =
+ BrowserList::GetInstance(browser()->host_desktop_type());
+ EXPECT_EQ(2u, active_browser_list->size());
+
+ // Close the first browser.
+ CloseBrowser(browser());
+ EXPECT_EQ(1u, active_browser_list->size());
+
+ // Restore tabs using the browser's recent tabs menu.
+ content::DOMMessageQueue queue;
+ Browser* browser = active_browser_list->get(0);
+ RecentTabsSubMenuModel menu(NULL, browser, NULL);
+ menu.ExecuteCommand(
+ RecentTabsSubMenuModel::GetFirstRecentTabsCommandId(), 0);
+ AwaitTabsReady(&queue, 2);
+
+ // There should be 3 restored tabs in the new browser.
+ EXPECT_EQ(2u, active_browser_list->size());
+ browser = active_browser_list->get(1);
+ EXPECT_EQ(3, browser->tab_strip_model()->count());
+
+ // The middle tab only should have visible disposition.
+ CheckVisbility(browser->tab_strip_model(), 1);
+}
+
+IN_PROC_BROWSER_TEST_F(BrowserTabRestoreTest, DelegateRestoreTabDisposition) {
+ // Create tabs.
+ CreateTestTabs(browser());
+ EXPECT_EQ(3, browser()->tab_strip_model()->count());
+
+ // Create a new browser.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), GURL(), NEW_WINDOW,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
+ BrowserList* active_browser_list =
+ BrowserList::GetInstance(browser()->host_desktop_type());
+ EXPECT_EQ(2u, active_browser_list->size());
+
+ // Close the first browser.
+ CloseBrowser(browser());
+ EXPECT_EQ(1u, active_browser_list->size());
+
+ // Check the browser has a delegated restore service.
+ Browser* browser = active_browser_list->get(0);
+ TabRestoreService* service =
+ TabRestoreServiceFactory::GetForProfile(browser->profile());
+ bool has_tab_restore_service = !!service;
+ ASSERT_TRUE(has_tab_restore_service);
+ TabRestoreServiceDelegate* delegate =
+ TabRestoreServiceDelegate::FindDelegateForWebContents(
+ browser->tab_strip_model()->GetActiveWebContents());
+ bool has_tab_restore_delegate = !!delegate;
+ ASSERT_TRUE(has_tab_restore_delegate);
+
+ // Restore tabs using that delegated restore service.
+ content::DOMMessageQueue queue;
+ service->RestoreMostRecentEntry(
+ delegate, browser->host_desktop_type());
+ AwaitTabsReady(&queue, 2);
+
+ // There should be 3 restored tabs in the new browser.
+ EXPECT_EQ(2u, active_browser_list->size());
+ browser = active_browser_list->get(1);
+ EXPECT_EQ(3, browser->tab_strip_model()->count());
+
+ // The middle tab only should have visible disposition.
+ CheckVisbility(browser->tab_strip_model(), 1);
+}
« no previous file with comments | « chrome/browser/ui/browser_tabrestore.cc ('k') | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698