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

Side by Side Diff: chrome/browser/ui/views/media_router/media_router_ui_browsertest.cc

Issue 1805393002: Added MediaRouterUIBrowserTest::toolbar_action_view_ to a Widget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Proposed solution. Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/thread_task_runner_handle.h" 6 #include "base/thread_task_runner_handle.h"
7 #include "chrome/browser/extensions/browser_action_test_util.h" 7 #include "chrome/browser/extensions/browser_action_test_util.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/browser/ui/toolbar/media_router_action.h" 11 #include "chrome/browser/ui/toolbar/media_router_action.h"
12 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 14 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
15 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 15 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
16 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" 16 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/test_navigation_observer.h" 22 #include "content/public/test/test_navigation_observer.h"
23 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
24 #include "ui/views/widget/widget.h"
24 25
25 namespace media_router { 26 namespace media_router {
26 27
27 class MediaRouterUIBrowserTest : public InProcessBrowserTest { 28 class MediaRouterUIBrowserTest : public InProcessBrowserTest {
28 public: 29 public:
29 MediaRouterUIBrowserTest() {} 30 MediaRouterUIBrowserTest() {}
30 ~MediaRouterUIBrowserTest() override {} 31 ~MediaRouterUIBrowserTest() override {}
31 32
32 void SetUpOnMainThread() override { 33 void SetUpOnMainThread() override {
33 InProcessBrowserTest::SetUpOnMainThread(); 34 InProcessBrowserTest::SetUpOnMainThread();
34 35
35 BrowserActionsContainer* browser_actions_container = 36 BrowserActionsContainer* browser_actions_container =
36 BrowserView::GetBrowserViewForBrowser(browser()) 37 BrowserView::GetBrowserViewForBrowser(browser())
37 ->toolbar() 38 ->toolbar()
38 ->browser_actions(); 39 ->browser_actions();
39 ASSERT_TRUE(browser_actions_container); 40 ASSERT_TRUE(browser_actions_container);
40 41
41 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), 42 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(),
42 false)); 43 false));
43 media_router_action_.reset(new MediaRouterAction(browser(), 44 media_router_action_.reset(new MediaRouterAction(browser(),
44 browser_action_test_util_->GetToolbarActionsBar())); 45 browser_action_test_util_->GetToolbarActionsBar()));
45 46
46 // Sets delegate on |media_router_action_|. 47 // Sets delegate on |media_router_action_|.
47 toolbar_action_view_.reset( 48 toolbar_action_view_.reset(
48 new ToolbarActionView(media_router_action_.get(), 49 new ToolbarActionView(media_router_action_.get(),
49 browser_actions_container)); 50 browser_actions_container));
51
52 toolbar_action_view_widget_.reset(new views::Widget);
53 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
54 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
55 toolbar_action_view_widget_->Init(params);
56 toolbar_action_view_widget_->Show();
57 toolbar_action_view_widget_->SetContentsView(toolbar_action_view_.get());
50 } 58 }
51 59
52 void TearDownOnMainThread() override { 60 void TearDownOnMainThread() override {
53 toolbar_action_view_.reset(); 61 toolbar_action_view_.reset();
54 media_router_action_.reset(); 62 media_router_action_.reset();
55 browser_action_test_util_.reset(); 63 browser_action_test_util_.reset();
56 InProcessBrowserTest::TearDownOnMainThread(); 64 InProcessBrowserTest::TearDownOnMainThread();
57 } 65 }
58 66
59 void OpenMediaRouterDialogAndWaitForNewWebContents() { 67 void OpenMediaRouterDialogAndWaitForNewWebContents() {
(...skipping 24 matching lines...) Expand all
84 EXPECT_TRUE(app_menu_button->IsMenuShowing()); 92 EXPECT_TRUE(app_menu_button->IsMenuShowing());
85 media_router_action_->ExecuteAction(true); 93 media_router_action_->ExecuteAction(true);
86 } 94 }
87 95
88 protected: 96 protected:
89 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. 97 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|.
90 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; 98 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
91 scoped_ptr<MediaRouterAction> media_router_action_; 99 scoped_ptr<MediaRouterAction> media_router_action_;
92 100
93 // ToolbarActionView constructed to set the delegate on |mr_action|. 101 // ToolbarActionView constructed to set the delegate on |mr_action|.
94 scoped_ptr<ToolbarActionView> toolbar_action_view_; 102 scoped_ptr<ToolbarActionView> toolbar_action_view_;
Evan Stade 2016/03/17 21:41:35 is this still the right ownership model? I'd expec
bruthig 2016/03/18 15:39:21 Good catch, updated. PTAL
103
104 // Hosts the |toolbar_action_view_|.
105 scoped_ptr<views::Widget> toolbar_action_view_widget_;
Evan Stade 2016/03/17 21:41:35 likewise aren't widgets usually self-owned? You ju
bruthig 2016/03/18 15:39:21 Is this what you are suggesting, using a raw point
95 }; 106 };
96 107
97 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, 108 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest,
98 OpenDialogWithMediaRouterAction) { 109 OpenDialogWithMediaRouterAction) {
99 // We start off at about:blank page. 110 // We start off at about:blank page.
100 // Make sure there is 1 tab and media router is enabled. 111 // Make sure there is 1 tab and media router is enabled.
101 ASSERT_EQ(1, browser()->tab_strip_model()->count()); 112 ASSERT_EQ(1, browser()->tab_strip_model()->count());
102 113
103 OpenMediaRouterDialogAndWaitForNewWebContents(); 114 OpenMediaRouterDialogAndWaitForNewWebContents();
104 115
105 // Reload the browser and wait. 116 // Reload the browser and wait.
106 content::TestNavigationObserver reload_observer( 117 content::TestNavigationObserver reload_observer(
107 browser()->tab_strip_model()->GetActiveWebContents()); 118 browser()->tab_strip_model()->GetActiveWebContents());
108 chrome::Reload(browser(), CURRENT_TAB); 119 chrome::Reload(browser(), CURRENT_TAB);
109 reload_observer.Wait(); 120 reload_observer.Wait();
110 121
111 // The reload should have removed the previously created dialog. 122 // The reload should have removed the previously created dialog.
112 // We expect a new dialog WebContents to be created by calling this. 123 // We expect a new dialog WebContents to be created by calling this.
113 OpenMediaRouterDialogAndWaitForNewWebContents(); 124 OpenMediaRouterDialogAndWaitForNewWebContents();
114 125
115 // Navigate away. 126 // Navigate away.
116 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 127 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
117 128
118 // The navigation should have removed the previously created dialog. 129 // The navigation should have removed the previously created dialog.
119 // We expect a new dialog WebContents to be created by calling this. 130 // We expect a new dialog WebContents to be created by calling this.
120 OpenMediaRouterDialogAndWaitForNewWebContents(); 131 OpenMediaRouterDialogAndWaitForNewWebContents();
121 } 132 }
122 133
123 } // namespace media_router 134 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698