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

Side by Side Diff: chrome/browser/ui/views/frame/browser_view_browsertest.cc

Issue 573893003: Avoid unnecessary visibility changes to BookmarkBarView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 2 trunk Created 6 years, 3 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 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 "chrome/browser/devtools/devtools_window_testing.h" 8 #include "chrome/browser/devtools/devtools_window_testing.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_tabstrip.h" 10 #include "chrome/browser/ui/browser_tabstrip.h"
10 #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"
13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h"
14 #include "chrome/common/url_constants.h"
11 #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"
17 #include "components/bookmarks/common/bookmark_pref_names.h"
12 #include "content/public/browser/invalidate_type.h" 18 #include "content/public/browser/invalidate_type.h"
13 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_observer.h" 20 #include "content/public/browser/web_contents_observer.h"
15 21
16 class BrowserViewTest : public InProcessBrowserTest { 22 class BrowserViewTest : public InProcessBrowserTest {
17 public: 23 public:
18 BrowserViewTest() : InProcessBrowserTest(), devtools_(NULL) {} 24 BrowserViewTest() : InProcessBrowserTest(), devtools_(NULL) {}
19 25
20 protected: 26 protected:
21 BrowserView* browser_view() { 27 BrowserView* browser_view() {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 CloseDevToolsWindow(); 165 CloseDevToolsWindow();
160 EXPECT_FALSE(devtools_web_view()->web_contents()); 166 EXPECT_FALSE(devtools_web_view()->web_contents());
161 EXPECT_EQ(full_bounds, devtools_web_view()->bounds()); 167 EXPECT_EQ(full_bounds, devtools_web_view()->bounds());
162 EXPECT_EQ(full_bounds, contents_web_view()->bounds()); 168 EXPECT_EQ(full_bounds, contents_web_view()->bounds());
163 169
164 browser_view()->UpdateDevTools(); 170 browser_view()->UpdateDevTools();
165 EXPECT_FALSE(devtools_web_view()->web_contents()); 171 EXPECT_FALSE(devtools_web_view()->web_contents());
166 EXPECT_EQ(full_bounds, devtools_web_view()->bounds()); 172 EXPECT_EQ(full_bounds, devtools_web_view()->bounds());
167 EXPECT_EQ(full_bounds, contents_web_view()->bounds()); 173 EXPECT_EQ(full_bounds, contents_web_view()->bounds());
168 } 174 }
175
176 class BookmarkBarViewObserverImpl : public BookmarkBarViewObserver {
177 public:
178 BookmarkBarViewObserverImpl() : change_count_(0) {
179 }
180
181 int change_count() const { return change_count_; }
182 void clear_change_count() { change_count_ = 0; }
183
184 // BookmarkBarViewObserver:
185 virtual void OnBookmarkBarVisibilityChanged() OVERRIDE {
186 change_count_++;
187 }
188
189 private:
190 int change_count_;
191
192 DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewObserverImpl);
193 };
194
195 // Verifies we don't unnecessarily change the visibility of the bookmarkbarview.
James Cook 2014/09/16 15:52:31 nit: "bookmarkbarview" to either "BookmarkBarView"
sky 2014/09/16 16:22:08 Done.
196 IN_PROC_BROWSER_TEST_F(BrowserViewTest, AvoidUnnecessaryVisibilityChanges) {
197 // Create two tabs, the first empty and the second the ntp. Make it so the
198 // bookmarkbar isn't shown (meaning it'll only be shown when on the ntp).
James Cook 2014/09/16 15:52:31 ditto: "bookmarkbar" just reads oddly to me
sky 2014/09/16 16:22:08 Done.
199 browser()->profile()->GetPrefs()->SetBoolean(
200 bookmarks::prefs::kShowBookmarkBar, false);
201 GURL new_tab_url(chrome::kChromeUINewTabURL);
202 chrome::AddTabAt(browser(), GURL(), -1, true);
203 ui_test_utils::NavigateToURL(browser(), new_tab_url);
204
205 ASSERT_TRUE(browser_view()->bookmark_bar());
206 BookmarkBarViewObserverImpl observer;
207 BookmarkBarView* bookmark_bar = browser_view()->bookmark_bar();
208 bookmark_bar->AddObserver(&observer);
209 EXPECT_TRUE(bookmark_bar->visible());
210
211 // Go to empty tab. Bookmark bar should hide.
212 browser()->tab_strip_model()->ActivateTabAt(0, true);
213 EXPECT_FALSE(bookmark_bar->visible());
214 EXPECT_EQ(1, observer.change_count());
215 observer.clear_change_count();
216
217 // Go to ntp tab. Bookmark bar should show.
218 browser()->tab_strip_model()->ActivateTabAt(1, true);
219 EXPECT_TRUE(bookmark_bar->visible());
220 EXPECT_EQ(1, observer.change_count());
221 observer.clear_change_count();
222
223 // Repeat with the bookmark bar always visible.
224 browser()->profile()->GetPrefs()->SetBoolean(
225 bookmarks::prefs::kShowBookmarkBar, true);
226 browser()->tab_strip_model()->ActivateTabAt(1, true);
227 EXPECT_TRUE(bookmark_bar->visible());
228 observer.clear_change_count();
229
230 browser()->tab_strip_model()->ActivateTabAt(0, true);
231 EXPECT_TRUE(bookmark_bar->visible());
232 EXPECT_EQ(0, observer.change_count());
233 observer.clear_change_count();
234
235 browser()->tab_strip_model()->ActivateTabAt(1, true);
236 EXPECT_TRUE(bookmark_bar->visible());
237 EXPECT_EQ(0, observer.change_count());
238 observer.clear_change_count();
239
240 browser_view()->bookmark_bar()->RemoveObserver(&observer);
241 }
James Cook 2014/09/16 15:52:31 Nice test.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698