summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-26 23:09:01 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-26 23:09:01 +0000
commit327f97ef60f125947b19d6ae8657b1c987b4a18f (patch)
tree9031d91f04266817eba9194239b6810d937ae76e
parentb8c80385367c19294edacd18400038e68a09c576 (diff)
downloadchromium_src-327f97ef60f125947b19d6ae8657b1c987b4a18f.zip
chromium_src-327f97ef60f125947b19d6ae8657b1c987b4a18f.tar.gz
chromium_src-327f97ef60f125947b19d6ae8657b1c987b4a18f.tar.bz2
Convert the bookmarks ui ui_test to a browser_test.
BUG=121574 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=134125 Review URL: https://chromiumcodereview.appspot.com/10174035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134174 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/webui/bookmarks_ui_browsertest.cc96
-rw-r--r--chrome/browser/ui/webui/bookmarks_ui_uitest.cc161
-rw-r--r--chrome/chrome_tests.gypi2
3 files changed, 97 insertions, 162 deletions
diff --git a/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc b/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc
new file mode 100644
index 0000000..e597425
--- /dev/null
+++ b/chrome/browser/ui/webui/bookmarks_ui_browsertest.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2012 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/test/ui/ui_test.h"
+
+#include "base/test/test_timeouts.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/web_contents.h"
+#include "content/test/test_navigation_observer.h"
+
+class BookmarksTest : public InProcessBrowserTest {
+ public:
+ BookmarksTest() {
+ EnableDOMAutomation();
+ }
+
+ void OpenBookmarksManager() {
+ TestNavigationObserver navigation_observer(
+ content::NotificationService::AllSources(), NULL, 2);
+
+ // Bring up the bookmarks manager tab.
+ browser()->OpenBookmarkManager();
+ navigation_observer.Wait();
+ }
+
+ void AssertIsBookmarksPage(content::WebContents* tab) {
+ GURL url;
+ std::string out;
+ ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
+ tab->GetRenderViewHost(), L"",
+ L"domAutomationController.send(location.protocol)", &out));
+ ASSERT_EQ("chrome-extension:", out);
+ ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
+ tab->GetRenderViewHost(), L"",
+ L"domAutomationController.send(location.pathname)", &out));
+ ASSERT_EQ("/main.html", out);
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(BookmarksTest, ShouldRedirectToExtension) {
+ ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL));
+ AssertIsBookmarksPage(browser()->GetSelectedWebContents());
+}
+
+IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandOpensBookmarksTab) {
+ ASSERT_EQ(1, browser()->tab_count());
+
+ // Bring up the bookmarks manager tab.
+ OpenBookmarksManager();
+ ASSERT_EQ(1, browser()->tab_count());
+ AssertIsBookmarksPage(browser()->GetSelectedWebContents());
+}
+
+// If this flakes on Mac, use: http://crbug.com/87200
+IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandAgainGoesBackToBookmarksTab) {
+ ui_test_utils::NavigateToURL(
+ browser(),
+ ui_test_utils::GetTestUrl(FilePath(),
+ FilePath().AppendASCII("simple.html")));
+ ASSERT_EQ(1, browser()->tab_count());
+
+ // Bring up the bookmarks manager tab.
+ OpenBookmarksManager();
+ ASSERT_EQ(2, browser()->tab_count());
+
+ AssertIsBookmarksPage(browser()->GetSelectedWebContents());
+
+ // Switch to first tab and run command again.
+ browser()->ActivateTabAt(0, true);
+ browser()->OpenBookmarkManager();
+
+ // Ensure the bookmarks ui tab is active.
+ ASSERT_EQ(1, browser()->active_index());
+ ASSERT_EQ(2, browser()->tab_count());
+}
+
+IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) {
+ TestNavigationObserver navigation_observer(
+ content::NotificationService::AllSources());
+ browser()->OpenBookmarkManager();
+ browser()->OpenBookmarkManager();
+ navigation_observer.Wait();
+
+ ASSERT_EQ(1, browser()->tab_count());
+}
+
+IN_PROC_BROWSER_TEST_F(BookmarksTest, BookmarksLoaded) {
+ ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL));
+ ASSERT_EQ(1, browser()->tab_count());
+ AssertIsBookmarksPage(browser()->GetSelectedWebContents());
+}
diff --git a/chrome/browser/ui/webui/bookmarks_ui_uitest.cc b/chrome/browser/ui/webui/bookmarks_ui_uitest.cc
deleted file mode 100644
index 0895d89..0000000
--- a/chrome/browser/ui/webui/bookmarks_ui_uitest.cc
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (c) 2012 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/test/ui/ui_test.h"
-
-#include "base/test/test_timeouts.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/test/automation/automation_proxy.h"
-#include "chrome/test/automation/browser_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/automation/window_proxy.h"
-
-class BookmarksUITest : public UITest {
- public:
- BookmarksUITest() {
- dom_automation_enabled_ = true;
- }
-
- bool WaitForBookmarksUI(TabProxy* tab) {
- return WaitUntilJavaScriptCondition(tab, L"",
- L"domAutomationController.send("
- L" location.protocol == 'chrome-extension:' && "
- L" document.readyState == 'complete')",
- TestTimeouts::large_test_timeout_ms());
- }
-
- scoped_refptr<TabProxy> GetBookmarksUITab() {
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- EXPECT_TRUE(browser.get());
- if (!browser.get())
- return NULL;
- scoped_refptr<TabProxy> tab = browser->GetActiveTab();
- EXPECT_TRUE(tab.get());
- if (!tab.get())
- return NULL;
- bool success = tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL));
- EXPECT_TRUE(success);
- if (!success)
- return NULL;
- success = WaitForBookmarksUI(tab);
- EXPECT_TRUE(success);
- if (!success)
- return NULL;
- return tab;
- }
-
- void AssertIsBookmarksPage(TabProxy* tab) {
- // tab->GetCurrentURL is not up to date.
- GURL url;
- std::wstring out;
- ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
- L"domAutomationController.send(location.protocol)", &out));
- ASSERT_EQ(L"chrome-extension:", out);
- ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
- L"domAutomationController.send(location.pathname)", &out));
- ASSERT_EQ(L"/main.html", out);
- }
-};
-
-TEST_F(BookmarksUITest, ShouldRedirectToExtension) {
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- ASSERT_TRUE(browser.get());
-
- int tab_count = -1;
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(1, tab_count);
-
- // Navigate to chrome
- scoped_refptr<TabProxy> tab = browser->GetActiveTab();
- ASSERT_TRUE(tab.get());
-
- ASSERT_TRUE(tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL)));
-
- // At this point the URL is chrome://bookmarks. We need to wait for the
- // redirect to happen.
- ASSERT_TRUE(WaitForBookmarksUI(tab));
-
- AssertIsBookmarksPage(tab);
-}
-
-TEST_F(BookmarksUITest, CommandOpensBookmarksTab) {
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- ASSERT_TRUE(browser.get());
-
- int tab_count = -1;
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(1, tab_count);
-
- // Bring up the bookmarks manager tab.
- ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(1, tab_count);
-
- scoped_refptr<TabProxy> tab = browser->GetActiveTab();
- ASSERT_TRUE(tab.get());
-
- ASSERT_TRUE(WaitForBookmarksUI(tab));
-
- AssertIsBookmarksPage(tab);
-}
-
-#if defined(OS_MACOSX)
-// Acting flaky on Mac: http://crbug.com/87200
-#define MAYBE_CommandAgainGoesBackToBookmarksTab DISABLED_CommandAgainGoesBackToBookmarksTab
-#else
-#define MAYBE_CommandAgainGoesBackToBookmarksTab CommandAgainGoesBackToBookmarksTab
-#endif
-TEST_F(BookmarksUITest, MAYBE_CommandAgainGoesBackToBookmarksTab) {
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- ASSERT_TRUE(browser.get());
-
- int tab_count = -1;
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- NavigateToURL(GURL("http://www.google.com/"));
- ASSERT_EQ(1, tab_count);
-
- // Bring up the bookmarks manager tab.
- ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
- ASSERT_TRUE(browser->WaitForTabToBecomeActive(
- 1, TestTimeouts::action_max_timeout_ms()));
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(2, tab_count);
-
- scoped_refptr<TabProxy> tab = browser->GetActiveTab();
- ASSERT_TRUE(tab.get());
- ASSERT_TRUE(WaitForBookmarksUI(tab));
- AssertIsBookmarksPage(tab);
-
- // Switch to first tab and run command again.
- ASSERT_TRUE(browser->ActivateTab(0));
- ASSERT_TRUE(browser->WaitForTabToBecomeActive(
- 0, TestTimeouts::action_max_timeout_ms()));
- ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
-
- // Ensure the bookmarks ui tab is active.
- ASSERT_TRUE(browser->WaitForTabToBecomeActive(
- 1, TestTimeouts::action_max_timeout_ms()));
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(2, tab_count);
-}
-
-TEST_F(BookmarksUITest, TwoCommandsOneTab) {
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- ASSERT_TRUE(browser.get());
-
- int tab_count = -1;
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(1, tab_count);
-
- ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
- ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
- ASSERT_TRUE(browser->GetTabCount(&tab_count));
- ASSERT_EQ(1, tab_count);
-}
-
-TEST_F(BookmarksUITest, BookmarksLoaded) {
- scoped_refptr<TabProxy> tab = GetBookmarksUITab();
- ASSERT_TRUE(tab.get());
-}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 30f4452..08b4cea 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -716,7 +716,6 @@
# less flakier.
'browser/process_singleton_linux_uitest.cc',
'browser/ui/tests/browser_uitest.cc',
- 'browser/ui/webui/bookmarks_ui_uitest.cc',
'browser/ui/webui/ntp/new_tab_ui_uitest.cc',
'browser/ui/webui/options2/chromeos/guest_mode_options_ui2_uitest.cc',
'browser/ui/webui/options2/options_ui2_uitest.cc',
@@ -2948,6 +2947,7 @@
'browser/ui/webui/test_chrome_web_ui_controller_factory_browsertest.cc',
'browser/ui/webui/bidi_checker_web_ui_test.cc',
'browser/ui/webui/bidi_checker_web_ui_test.h',
+ 'browser/ui/webui/bookmarks_ui_browsertest.cc',
'browser/ui/webui/extensions/extension_settings_browsertest.js',
'browser/ui/webui/net_internals/net_internals_ui_browsertest.cc',
'browser/ui/webui/net_internals/net_internals_ui_browsertest.h',