OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/browser.h" | |
6 #include "chrome/browser/ui/browser_commands.h" | |
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
8 #include "chrome/browser/ui/toolbar/media_router_action.h" | |
9 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | |
10 #include "chrome/browser/ui/views/frame/browser_view.h" | |
11 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | |
12 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | |
13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | |
14 #include "chrome/test/base/in_process_browser_test.h" | |
15 #include "chrome/test/base/ui_test_utils.h" | |
16 #include "content/public/browser/web_contents.h" | |
17 #include "content/public/test/test_navigation_observer.h" | |
18 #include "content/public/test/test_utils.h" | |
19 | |
20 namespace media_router { | |
21 | |
22 class MediaRouterUIBrowserTest : public InProcessBrowserTest { | |
23 public: | |
24 MediaRouterUIBrowserTest() {} | |
25 ~MediaRouterUIBrowserTest() override {} | |
26 | |
27 void SetUpOnMainThread() override { | |
28 InProcessBrowserTest::SetUpOnMainThread(); | |
29 | |
30 BrowserActionsContainer* browser_actions_container = | |
31 BrowserView::GetBrowserViewForBrowser(browser()) | |
32 ->toolbar() | |
33 ->browser_actions(); | |
34 ASSERT_TRUE(browser_actions_container); | |
35 | |
36 media_router_action_.reset(new MediaRouterAction); | |
37 | |
38 // Sets delegate on |media_router_action_|. | |
39 toolbar_action_view_.reset( | |
40 new ToolbarActionView(media_router_action_.get(), browser()->profile(), | |
41 browser_actions_container)); | |
42 } | |
43 | |
44 void OpenMediaRouterDialogAndWaitForNewWebContents() { | |
45 content::TestNavigationObserver nav_observer(NULL); | |
46 nav_observer.StartWatchingNewWebContents(); | |
47 media_router_action_->ExecuteAction(true); | |
48 nav_observer.Wait(); | |
49 nav_observer.StopWatchingNewWebContents(); | |
50 } | |
51 | |
52 protected: | |
53 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. | |
54 scoped_ptr<MediaRouterAction> media_router_action_; | |
55 | |
56 // ToolbarActionView constructed to set the delegate on |mr_action|. | |
57 scoped_ptr<ToolbarActionView> toolbar_action_view_; | |
58 }; | |
59 | |
60 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | |
Peter Kasting
2015/06/04 07:13:03
This test is better now, but it still wouldn't go
imcheng (use chromium acct)
2015/06/04 16:45:43
Done.
| |
61 OpenDialogWithMediaRouterAction) { | |
62 // We start off at about:blank page. | |
63 // Make sure there is 1 tab and media router is enabled. | |
64 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
65 | |
66 OpenMediaRouterDialogAndWaitForNewWebContents(); | |
67 | |
68 // Reload the browser and wait. | |
69 content::TestNavigationObserver reload_observer( | |
70 browser()->tab_strip_model()->GetActiveWebContents()); | |
71 chrome::Reload(browser(), CURRENT_TAB); | |
72 reload_observer.Wait(); | |
73 | |
74 // The reload should have removed the previously created dialog. | |
75 // We expect a new dialog WebContents to be created by calling this. | |
Peter Kasting
2015/06/04 07:13:03
If the previous dialog wasn't removed or a new Web
imcheng (use chromium acct)
2015/06/04 16:45:43
I believe browser tests have a builtin timeout (so
| |
76 OpenMediaRouterDialogAndWaitForNewWebContents(); | |
77 | |
78 // Navigate away and wait. | |
79 content::TestNavigationObserver nav_observer( | |
80 browser()->tab_strip_model()->GetActiveWebContents(), 1); | |
81 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
82 nav_observer.Wait(); | |
83 | |
84 // The navigation should have removed the previously created dialog. | |
85 // We expect a new dialog WebContents to be created by calling this. | |
86 OpenMediaRouterDialogAndWaitForNewWebContents(); | |
87 } | |
88 | |
89 } // namespace media_router | |
OLD | NEW |