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

Unified Diff: chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc

Issue 2621723003: [Media Router] Add browser tests for showing the dialog (Closed)
Patch Set: Address Jennifer's comments Created 3 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc
diff --git a/chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc b/chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc
index 7455c4bfd6e2c40cfbe6e125c0f8a24ad518d9a6..9a372f342bd9acb4b06add6ecb231afcb1f5f2ca 100644
--- a/chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc
+++ b/chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc
@@ -4,8 +4,10 @@
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/media/router/media_router_ui_service.h"
+#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
@@ -14,6 +16,7 @@
#include "chrome/browser/ui/toolbar/media_router_action_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/toolbar/app_menu.h"
#include "chrome/browser/ui/views/toolbar/app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
@@ -22,7 +25,9 @@
#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/navigation_entry.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/context_menu_params.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "ui/views/widget/widget.h"
@@ -58,10 +63,7 @@ class MediaRouterUIBrowserTest : public InProcessBrowserTest {
content::TestNavigationObserver nav_observer(NULL);
nav_observer.StartWatchingNewWebContents();
- AppMenuButton* app_menu_button =
- BrowserView::GetBrowserViewForBrowser(browser())
- ->toolbar()
- ->app_menu_button();
+ AppMenuButton* app_menu_button = GetAppMenuButton();
// When the Media Router Action executes, it opens a dialog with web
// contents to chrome://media-router.
@@ -105,6 +107,12 @@ class MediaRouterUIBrowserTest : public InProcessBrowserTest {
ComponentToolbarActionsFactory::kMediaRouterActionId, always_show);
}
+ AppMenuButton* GetAppMenuButton() {
+ return BrowserView::GetBrowserViewForBrowser(browser())
+ ->toolbar()
+ ->app_menu_button();
+ }
+
protected:
ToolbarActionsBar* toolbar_actions_bar_ = nullptr;
@@ -147,6 +155,98 @@ IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest,
SetAlwaysShowActionPref(false);
}
+IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, OpenDialogFromContextMenu) {
+ // Start with one tab showing about:blank.
+ ASSERT_EQ(1, browser()->tab_strip_model()->count());
+
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ MediaRouterDialogController* dialog_controller =
+ MediaRouterDialogController::GetOrCreateForWebContents(
+ browser()->tab_strip_model()->GetActiveWebContents());
+ content::ContextMenuParams params;
+ params.page_url = web_contents->GetController().GetActiveEntry()->GetURL();
+ TestRenderViewContextMenu menu(web_contents->GetMainFrame(), params);
+ menu.Init();
+
+ ASSERT_TRUE(menu.IsItemPresent(IDC_ROUTE_MEDIA));
+ ASSERT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
+ menu.ExecuteCommand(IDC_ROUTE_MEDIA, 0);
+ EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog());
+
+ // Executing the command again should be a no-op, and there should only be one
+ // dialog opened per tab.
+ menu.ExecuteCommand(IDC_ROUTE_MEDIA, 0);
+ EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog());
+ dialog_controller->HideMediaRouterDialog();
+ EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
+}
+
+IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, OpenDialogFromAppMenu) {
+ // Start with one tab showing about:blank.
+ ASSERT_EQ(1, browser()->tab_strip_model()->count());
+
+ AppMenuButton* menu_button = GetAppMenuButton();
+ base::RunLoop run_loop;
+ menu_button->ShowMenu(false);
+ run_loop.RunUntilIdle();
+
+ MediaRouterDialogController* dialog_controller =
+ MediaRouterDialogController::GetOrCreateForWebContents(
+ browser()->tab_strip_model()->GetActiveWebContents());
+ AppMenu* menu = menu_button->app_menu_for_testing();
+ ASSERT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
+ menu->ExecuteCommand(IDC_ROUTE_MEDIA, 0);
+ EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog());
+
+ // Executing the command again should be a no-op, and there should only be one
+ // dialog opened per tab.
+ menu->ExecuteCommand(IDC_ROUTE_MEDIA, 0);
+ EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog());
+ dialog_controller->HideMediaRouterDialog();
+ EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog());
+}
+
+IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, OpenDialogsInMultipleTabs) {
+ // Start with two tabs.
+ chrome::NewTab(browser());
+ ASSERT_EQ(2, browser()->tab_strip_model()->count());
+ MediaRouterDialogController* dialog_controller1 =
+ MediaRouterDialogController::GetOrCreateForWebContents(
+ browser()->tab_strip_model()->GetWebContentsAt(0));
+ MediaRouterDialogController* dialog_controller2 =
+ MediaRouterDialogController::GetOrCreateForWebContents(
+ browser()->tab_strip_model()->GetWebContentsAt(1));
+
+ // Show the media router action on the toolbar.
+ SetAlwaysShowActionPref(true);
+
+ // Open a dialog in the first tab using the toolbar action.
+ browser()->tab_strip_model()->ActivateTabAt(0, true);
+ EXPECT_FALSE(dialog_controller1->IsShowingMediaRouterDialog());
+ GetMediaRouterAction()->ExecuteAction(true);
+ EXPECT_TRUE(dialog_controller1->IsShowingMediaRouterDialog());
+
+ // Move to the second tab, which shouldn't have a dialog at first. Open and
+ // close a dialog in that tab.
+ browser()->tab_strip_model()->ActivateTabAt(1, true);
+ EXPECT_FALSE(dialog_controller2->IsShowingMediaRouterDialog());
+ GetMediaRouterAction()->ExecuteAction(true);
+ EXPECT_TRUE(dialog_controller2->IsShowingMediaRouterDialog());
+ GetMediaRouterAction()->ExecuteAction(true);
+ EXPECT_FALSE(dialog_controller2->IsShowingMediaRouterDialog());
+
+ // Move back to the first tab, whose dialog should still be open. Hide the
+ // dialog.
+ browser()->tab_strip_model()->ActivateTabAt(0, true);
+ EXPECT_TRUE(dialog_controller1->IsShowingMediaRouterDialog());
+ GetMediaRouterAction()->ExecuteAction(true);
+ EXPECT_FALSE(dialog_controller1->IsShowingMediaRouterDialog());
+
+ // Reset the preference showing the toolbar action.
+ SetAlwaysShowActionPref(false);
+}
+
IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest,
EphemeralToolbarIconForRoutesAndIssues) {
action_controller_->OnIssue(issue_);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698