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

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

Issue 181403006: Make TestingProfile auto-create incognito profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove broken and no-longer-applicable test Created 6 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 | Annotate | Revision Log
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 "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 9 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
10 #include "chrome/browser/ui/views/frame/browser_view_layout.h" 10 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 header_offset.y(); 205 header_offset.y();
206 206
207 // The web contents should be flush with the bottom of the header. 207 // The web contents should be flush with the bottom of the header.
208 EXPECT_EQ(bottom_of_header, contents_container->y()); 208 EXPECT_EQ(bottom_of_header, contents_container->y());
209 209
210 // The find bar should overlap the 1px header/web-contents separator at the 210 // The find bar should overlap the 1px header/web-contents separator at the
211 // bottom of the header. 211 // bottom of the header.
212 EXPECT_EQ(browser_view()->frame()->GetTopInset() - 1, 212 EXPECT_EQ(browser_view()->frame()->GetTopInset() - 1,
213 browser_view()->GetFindBarBoundingBox().y()); 213 browser_view()->GetFindBarBoundingBox().y());
214 } 214 }
215
216 #if defined(OS_WIN)
217
218 // This class provides functionality to test the incognito window/normal window
219 // switcher button which is added to Windows 8 metro Chrome.
220 // We create the BrowserView ourselves in the
221 // BrowserWithTestWindowTest::CreateBrowserWindow function override and add the
222 // switcher button to the view. We also provide an incognito profile to ensure
223 // that the switcher button is visible.
224 class BrowserViewIncognitoSwitcherTest : public TestWithBrowserView {
225 public:
226 // Subclass of BrowserView, which overrides the GetRestoreBounds/IsMaximized
227 // functions to return dummy values. This is needed because we create the
228 // BrowserView instance ourselves and initialize it with the created Browser
229 // instance. These functions get called before the underlying Widget is
230 // initialized which causes a crash while dereferencing a null native_widget_
231 // pointer in the Widget class.
232 class TestBrowserView : public BrowserView {
233 public:
234 virtual ~TestBrowserView() {}
235
236 virtual gfx::Rect GetRestoredBounds() const OVERRIDE {
237 return gfx::Rect();
238 }
239 virtual bool IsMaximized() const OVERRIDE {
240 return false;
241 }
242 };
243
244 BrowserViewIncognitoSwitcherTest()
245 : browser_view_(NULL) {}
246
247 virtual void SetUp() OVERRIDE {
248 TestWithBrowserView::SetUp();
249 browser_view_->Init(browser());
250 (new BrowserFrame(browser_view_))->InitBrowserFrame();
251 browser_view_->SetBounds(gfx::Rect(10, 10, 500, 500));
252 browser_view_->Show();
253 }
254
255 virtual void TearDown() OVERRIDE {
256 // ok to release the window_ pointer because BrowserViewTest::TearDown
257 // deletes the BrowserView instance created.
258 release_browser_window();
259 BrowserViewTest::TearDown();
260 browser_view_ = NULL;
261 }
262
263 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE {
264 // We need an incognito profile for the window switcher button to be
265 // visible.
266 // This profile instance is owned by the TestingProfile instance within the
267 // BrowserWithTestWindowTest class.
268 TestingProfile::Builder builder;
269 builder.SetIncognito();
270 GetProfile()->SetOffTheRecordProfile(builder.Build());
271
272 browser_view_ = new TestBrowserView();
273
274 views::ImageButton* switcher_button = new views::ImageButton(NULL);
275 // The button in the incognito window has the hot-cold images inverted
276 // with respect to the regular browser window.
277 switcher_button->SetImage(
278 views::ImageButton::STATE_NORMAL,
279 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
280 IDR_INCOGNITO_SWITCH_OFF));
281 switcher_button->SetImage(
282 views::ImageButton::STATE_HOVERED,
283 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
284 IDR_INCOGNITO_SWITCH_ON));
285 switcher_button->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
286 views::ImageButton::ALIGN_MIDDLE);
287
288 browser_view_->SetWindowSwitcherButton(switcher_button);
289 return browser_view_;
290 }
291
292 private:
293 BrowserView* browser_view_;
294
295 DISALLOW_COPY_AND_ASSIGN(BrowserViewIncognitoSwitcherTest);
296 };
297
298 // Test whether the windows incognito/normal browser window switcher button
299 // is the event handler for a point within its bounds. The event handler for
300 // a point in the View class is dependent on the order in which children are
301 // added to it. This test ensures that we don't regress in the window switcher
302 // functionality when additional children are added to the BrowserView class.
303 TEST_F(BrowserViewIncognitoSwitcherTest,
304 BrowserViewIncognitoSwitcherEventHandlerTest) {
305 // |browser_view_| owns the Browser, not the test class.
306 EXPECT_TRUE(browser_view()->browser());
307 // Test initial state.
308 EXPECT_TRUE(browser_view()->IsTabStripVisible());
309 // Validate whether the window switcher button is the target for the position
310 // passed in.
311 gfx::Point switcher_point(browser_view()->window_switcher_button()->x() + 2,
312 browser_view()->window_switcher_button()->y());
313 EXPECT_EQ(browser_view()->GetEventHandlerForPoint(switcher_point),
314 browser_view()->window_switcher_button());
315 }
316 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller_unittest.cc ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698