OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/devtools/devtools_window_testing.h" | 8 #include "chrome/browser/devtools/devtools_window_testing.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 12 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h" | 13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "components/bookmarks/common/bookmark_pref_names.h" | 17 #include "components/bookmarks/common/bookmark_pref_names.h" |
18 #include "content/public/browser/invalidate_type.h" | 18 #include "content/public/browser/invalidate_type.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "ui/base/ui_base_types.h" |
21 | 22 |
22 class BrowserViewTest : public InProcessBrowserTest { | 23 class BrowserViewTest : public InProcessBrowserTest { |
23 public: | 24 public: |
24 BrowserViewTest() : InProcessBrowserTest(), devtools_(nullptr) {} | 25 BrowserViewTest() : InProcessBrowserTest(), devtools_(nullptr) {} |
25 | 26 |
26 protected: | 27 protected: |
27 BrowserView* browser_view() { | 28 BrowserView* browser_view() { |
28 return BrowserView::GetBrowserViewForBrowser(browser()); | 29 return BrowserView::GetBrowserViewForBrowser(browser()); |
29 } | 30 } |
30 | 31 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 other_->NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>( | 72 other_->NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>( |
72 content::INVALIDATE_TYPE_URL | content::INVALIDATE_TYPE_LOAD)); | 73 content::INVALIDATE_TYPE_URL | content::INVALIDATE_TYPE_LOAD)); |
73 } | 74 } |
74 | 75 |
75 private: | 76 private: |
76 content::WebContents* other_; | 77 content::WebContents* other_; |
77 | 78 |
78 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); | 79 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); |
79 }; | 80 }; |
80 | 81 |
| 82 class WebContentsShowHideObserver : public content::WebContentsObserver { |
| 83 public: |
| 84 WebContentsShowHideObserver(content::WebContents* web_contents, |
| 85 const base::Closure& callback) |
| 86 : WebContentsObserver(web_contents), |
| 87 callback_(callback), |
| 88 show_state_(ui::SHOW_STATE_DEFAULT) {} |
| 89 |
| 90 // WebContentsObserver. |
| 91 virtual void WasHidden() override { |
| 92 show_state_ = ui::SHOW_STATE_INACTIVE; |
| 93 callback_.Run(); |
| 94 } |
| 95 |
| 96 virtual void WasShown() override { |
| 97 show_state_ = ui::SHOW_STATE_NORMAL; |
| 98 callback_.Run(); |
| 99 } |
| 100 |
| 101 bool shown() { return show_state_ == ui::SHOW_STATE_NORMAL; } |
| 102 bool hidden() { return show_state_ == ui::SHOW_STATE_INACTIVE; } |
| 103 |
| 104 private: |
| 105 base::Closure callback_; |
| 106 ui::WindowShowState show_state_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(WebContentsShowHideObserver); |
| 109 }; |
| 110 |
81 } // namespace | 111 } // namespace |
82 | 112 |
83 // Verifies don't crash when CloseNow() is invoked with two tabs in a browser. | 113 // Verifies don't crash when CloseNow() is invoked with two tabs in a browser. |
84 // Additionally when one of the tabs is destroyed NotifyNavigationStateChanged() | 114 // Additionally when one of the tabs is destroyed NotifyNavigationStateChanged() |
85 // is invoked on the other. | 115 // is invoked on the other. |
86 IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabs) { | 116 IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabs) { |
87 Browser* browser2 = | 117 Browser* browser2 = |
88 new Browser(Browser::CreateParams(browser()->profile(), | 118 new Browser(Browser::CreateParams(browser()->profile(), |
89 browser()->host_desktop_type())); | 119 browser()->host_desktop_type())); |
90 chrome::AddTabAt(browser2, GURL(), -1, true); | 120 chrome::AddTabAt(browser2, GURL(), -1, true); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 EXPECT_EQ(0, observer.change_count()); | 260 EXPECT_EQ(0, observer.change_count()); |
231 observer.clear_change_count(); | 261 observer.clear_change_count(); |
232 | 262 |
233 browser()->tab_strip_model()->ActivateTabAt(1, true); | 263 browser()->tab_strip_model()->ActivateTabAt(1, true); |
234 EXPECT_TRUE(bookmark_bar->visible()); | 264 EXPECT_TRUE(bookmark_bar->visible()); |
235 EXPECT_EQ(0, observer.change_count()); | 265 EXPECT_EQ(0, observer.change_count()); |
236 observer.clear_change_count(); | 266 observer.clear_change_count(); |
237 | 267 |
238 browser_view()->bookmark_bar()->RemoveObserver(&observer); | 268 browser_view()->bookmark_bar()->RemoveObserver(&observer); |
239 } | 269 } |
| 270 |
| 271 IN_PROC_BROWSER_TEST_F(BrowserViewTest, MinimizeHidesWebContents) { |
| 272 // Minimizing the window should cause the active WebContents to be hidden. |
| 273 { |
| 274 base::RunLoop run_loop; |
| 275 WebContentsShowHideObserver observed( |
| 276 browser()->tab_strip_model()->GetActiveWebContents(), |
| 277 run_loop.QuitClosure()); |
| 278 |
| 279 ASSERT_FALSE(observed.hidden()); |
| 280 ASSERT_FALSE(observed.shown()); |
| 281 browser()->window()->Minimize(); |
| 282 if (!observed.hidden()) |
| 283 run_loop.Run(); |
| 284 ASSERT_TRUE(observed.hidden()); |
| 285 ASSERT_FALSE(observed.shown()); |
| 286 } |
| 287 |
| 288 // Restoring the window should cause the active WebContents to be shown. |
| 289 { |
| 290 base::RunLoop run_loop; |
| 291 WebContentsShowHideObserver observed( |
| 292 browser()->tab_strip_model()->GetActiveWebContents(), |
| 293 run_loop.QuitClosure()); |
| 294 |
| 295 ASSERT_FALSE(observed.hidden()); |
| 296 ASSERT_FALSE(observed.shown()); |
| 297 browser()->window()->Restore(); |
| 298 if (!observed.shown()) |
| 299 run_loop.Run(); |
| 300 ASSERT_TRUE(observed.shown()); |
| 301 ASSERT_FALSE(observed.hidden()); |
| 302 } |
| 303 } |
OLD | NEW |