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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
(Empty)
1 // Copyright 2012 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 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
6
7 #include "chrome/browser/instant/instant_model.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_view.h"
16 #import "testing/gtest_mac.h"
17
18 class OverlayableContentsControllerTest : public InProcessBrowserTest {
19 public:
20 OverlayableContentsControllerTest() {
21 }
22
23 virtual void SetUpOnMainThread() OVERRIDE {
24 web_contents_.reset(content::WebContents::Create(
25 content::WebContents::CreateParams(browser()->profile())));
26 controller_.reset([[OverlayableContentsController alloc]
27 initWithBrowser:browser()
28 windowController:nil]);
29 [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)];
30 instant_model_.AddObserver([controller_ instantOverlayController]);
31 }
32
33 virtual void CleanUpOnMainThread() OVERRIDE {
34 instant_model_.RemoveObserver([controller_ instantOverlayController]);
35 controller_.reset();
36 web_contents_.reset();
37 }
38
39 void VerifyOverlayFrame(CGFloat expected_height, BOOL is_height_in_pixels) {
40 NSRect container_bounds = [[controller_ view] bounds];
41 NSRect overlay_frame = [web_contents_->GetView()->GetNativeView() frame];
42
43 EXPECT_EQ(NSMinX(container_bounds), NSMinX(overlay_frame));
44 EXPECT_EQ(NSWidth(container_bounds), NSWidth(overlay_frame));
45 if (is_height_in_pixels) {
46 EXPECT_EQ(expected_height, NSHeight(overlay_frame));
47 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame));
48 } else {
49 EXPECT_EQ((expected_height * NSHeight(container_bounds)) / 100,
50 NSHeight(overlay_frame));
51 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame));
52 }
53 }
54
55 protected:
56 InstantModel instant_model_;
57 scoped_ptr<content::WebContents> web_contents_;
58 scoped_nsobject<OverlayableContentsController> controller_;
59 };
60
61 // Verify that the view is correctly laid out when size is specified in percent.
62 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePerecent) {
63 CGFloat expected_height = 30;
64 BOOL is_height_in_pixels = NO;
65 instant_model_.SetOverlayState(
66 web_contents_.get(), expected_height, is_height_in_pixels);
67
68 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview],
69 [controller_ view]);
70 VerifyOverlayFrame(expected_height, is_height_in_pixels);
71
72 // Resize the view and verify that the overlay is also resized.
73 [[controller_ view] setFrameSize:NSMakeSize(300, 400)];
74 VerifyOverlayFrame(expected_height, is_height_in_pixels);
75 }
76
77 // Verify that the view is correctly laid out when size is specified in pixels.
78 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePixels) {
79 CGFloat expected_height = 30;
80 BOOL is_height_in_pixels = YES;
81 instant_model_.SetOverlayState(
82 web_contents_.get(), expected_height, is_height_in_pixels);
83
84 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview],
85 [controller_ view]);
86 VerifyOverlayFrame(expected_height, is_height_in_pixels);
87
88 // Resize the view and verify that the overlay is also resized.
89 [[controller_ view] setFrameSize:NSMakeSize(300, 400)];
90 VerifyOverlayFrame(expected_height, is_height_in_pixels);
91 }
92
93 // Verify that a shadow is not shown when the overlay covers the entire page.
94 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) {
95 instant_model_.SetOverlayState(web_contents_.get(), 100, NO);
96 EXPECT_FALSE([controller_ dropShadowView]);
97 EXPECT_FALSE([controller_ drawDropShadow]);
98 }
99
100 // Verify that a shadow is shown when the overlay is in search mode.
101 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, ShadowInSearch) {
102 instant_model_.SetOverlayState(web_contents_.get(), mode, 10, NO);
103 EXPECT_TRUE([controller_ dropShadowView]);
104 EXPECT_TRUE([controller_ drawDropShadow]);
105 EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]);
106
107 NSRect dropShadowFrame = [[controller_ dropShadowView] frame];
108 NSRect controllerBounds = [[controller_ view] bounds];
109 EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame));
110 EXPECT_EQ([OverlayDropShadowView preferredHeight],
111 NSHeight(dropShadowFrame));
112 }
113
114 // Verify that the shadow is hidden when hiding the overlay.
115 IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) {
116 instant_model_.SetOverlayState(web_contents_.get(), mode, 10, NO);
117 EXPECT_TRUE([controller_ dropShadowView]);
118
119 [controller_ onActivateTabWithContents:web_contents_.get()];
120 EXPECT_FALSE([controller_ dropShadowView]);
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698