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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm
diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..9cb173b7de59707d4d7db1c3625f82cfbc3caaae
--- /dev/null
+++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm
@@ -0,0 +1,121 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
+
+#include "chrome/browser/instant/instant_model.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/cocoa/browser_window_controller.h"
+#include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#import "testing/gtest_mac.h"
+
+class OverlayableContentsControllerTest : public InProcessBrowserTest {
+ public:
+ OverlayableContentsControllerTest() {
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ web_contents_.reset(content::WebContents::Create(
+ content::WebContents::CreateParams(browser()->profile())));
+ controller_.reset([[OverlayableContentsController alloc]
+ initWithBrowser:browser()
+ windowController:nil]);
+ [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)];
+ instant_model_.AddObserver([controller_ instantOverlayController]);
+ }
+
+ virtual void CleanUpOnMainThread() OVERRIDE {
+ instant_model_.RemoveObserver([controller_ instantOverlayController]);
+ controller_.reset();
+ web_contents_.reset();
+ }
+
+ void VerifyOverlayFrame(CGFloat expected_height, BOOL is_height_in_pixels) {
+ NSRect container_bounds = [[controller_ view] bounds];
+ NSRect overlay_frame = [web_contents_->GetView()->GetNativeView() frame];
+
+ EXPECT_EQ(NSMinX(container_bounds), NSMinX(overlay_frame));
+ EXPECT_EQ(NSWidth(container_bounds), NSWidth(overlay_frame));
+ if (is_height_in_pixels) {
+ EXPECT_EQ(expected_height, NSHeight(overlay_frame));
+ EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame));
+ } else {
+ EXPECT_EQ((expected_height * NSHeight(container_bounds)) / 100,
+ NSHeight(overlay_frame));
+ EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame));
+ }
+ }
+
+ protected:
+ InstantModel instant_model_;
+ scoped_ptr<content::WebContents> web_contents_;
+ scoped_nsobject<OverlayableContentsController> controller_;
+};
+
+// Verify that the view is correctly laid out when size is specified in percent.
+IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePerecent) {
+ CGFloat expected_height = 30;
+ BOOL is_height_in_pixels = NO;
+ instant_model_.SetOverlayState(
+ web_contents_.get(), expected_height, is_height_in_pixels);
+
+ EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview],
+ [controller_ view]);
+ VerifyOverlayFrame(expected_height, is_height_in_pixels);
+
+ // Resize the view and verify that the overlay is also resized.
+ [[controller_ view] setFrameSize:NSMakeSize(300, 400)];
+ VerifyOverlayFrame(expected_height, is_height_in_pixels);
+}
+
+// Verify that the view is correctly laid out when size is specified in pixels.
+IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePixels) {
+ CGFloat expected_height = 30;
+ BOOL is_height_in_pixels = YES;
+ instant_model_.SetOverlayState(
+ web_contents_.get(), expected_height, is_height_in_pixels);
+
+ EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview],
+ [controller_ view]);
+ VerifyOverlayFrame(expected_height, is_height_in_pixels);
+
+ // Resize the view and verify that the overlay is also resized.
+ [[controller_ view] setFrameSize:NSMakeSize(300, 400)];
+ VerifyOverlayFrame(expected_height, is_height_in_pixels);
+}
+
+// Verify that a shadow is not shown when the overlay covers the entire page.
+IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) {
+ instant_model_.SetOverlayState(web_contents_.get(), 100, NO);
+ EXPECT_FALSE([controller_ dropShadowView]);
+ EXPECT_FALSE([controller_ drawDropShadow]);
+}
+
+// Verify that a shadow is shown when the overlay is in search mode.
+IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, ShadowInSearch) {
+ instant_model_.SetOverlayState(web_contents_.get(), mode, 10, NO);
+ EXPECT_TRUE([controller_ dropShadowView]);
+ EXPECT_TRUE([controller_ drawDropShadow]);
+ EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]);
+
+ NSRect dropShadowFrame = [[controller_ dropShadowView] frame];
+ NSRect controllerBounds = [[controller_ view] bounds];
+ EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame));
+ EXPECT_EQ([OverlayDropShadowView preferredHeight],
+ NSHeight(dropShadowFrame));
+}
+
+// Verify that the shadow is hidden when hiding the overlay.
+IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) {
+ instant_model_.SetOverlayState(web_contents_.get(), mode, 10, NO);
+ EXPECT_TRUE([controller_ dropShadowView]);
+
+ [controller_ onActivateTabWithContents:web_contents_.get()];
+ EXPECT_FALSE([controller_ dropShadowView]);
+}

Powered by Google App Engine
This is Rietveld 408576698