OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" | 5 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" |
6 | 6 |
7 #include "chrome/browser/instant/instant_model.h" | 7 #include "chrome/browser/instant/instant_model.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
12 #include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h" | 12 #include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h" |
13 #include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" | 13 #include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_view.h" |
16 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
17 | 18 |
18 class PreviewableContentsControllerTest : public InProcessBrowserTest { | 19 class PreviewableContentsControllerTest : public InProcessBrowserTest { |
19 public: | 20 public: |
20 PreviewableContentsControllerTest() : instant_model_(NULL) { | 21 PreviewableContentsControllerTest() : instant_model_(NULL) { |
21 } | 22 } |
22 | 23 |
23 virtual void SetUpOnMainThread() OVERRIDE { | 24 virtual void SetUpOnMainThread() OVERRIDE { |
24 web_contents_.reset(content::WebContents::Create( | 25 web_contents_.reset(content::WebContents::Create( |
25 content::WebContents::CreateParams(browser()->profile()))); | 26 content::WebContents::CreateParams(browser()->profile()))); |
(...skipping 10 matching lines...) Expand all Loading... |
36 instant_model_.RemoveObserver([controller_ instantPreviewController]); | 37 instant_model_.RemoveObserver([controller_ instantPreviewController]); |
37 instant_model_.SetPreviewContents(NULL); | 38 instant_model_.SetPreviewContents(NULL); |
38 controller_.reset(); | 39 controller_.reset(); |
39 web_contents_.reset(); | 40 web_contents_.reset(); |
40 } | 41 } |
41 | 42 |
42 void VerifyPreviewFrame(CGFloat expected_height, | 43 void VerifyPreviewFrame(CGFloat expected_height, |
43 InstantSizeUnits units) { | 44 InstantSizeUnits units) { |
44 NSRect container_bounds = [[controller_ view] bounds]; | 45 NSRect container_bounds = [[controller_ view] bounds]; |
45 NSRect preview_frame = | 46 NSRect preview_frame = |
46 [web_contents_->GetNativeView() frame]; | 47 [web_contents_->GetView()->GetNativeView() frame]; |
47 | 48 |
48 EXPECT_EQ(NSMinX(container_bounds), NSMinX(preview_frame)); | 49 EXPECT_EQ(NSMinX(container_bounds), NSMinX(preview_frame)); |
49 EXPECT_EQ(NSWidth(container_bounds), NSWidth(preview_frame)); | 50 EXPECT_EQ(NSWidth(container_bounds), NSWidth(preview_frame)); |
50 switch (units) { | 51 switch (units) { |
51 case INSTANT_SIZE_PIXELS: | 52 case INSTANT_SIZE_PIXELS: |
52 EXPECT_EQ(expected_height, NSHeight(preview_frame)); | 53 EXPECT_EQ(expected_height, NSHeight(preview_frame)); |
53 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(preview_frame)); | 54 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(preview_frame)); |
54 break; | 55 break; |
55 case INSTANT_SIZE_PERCENT: | 56 case INSTANT_SIZE_PERCENT: |
56 EXPECT_EQ((expected_height * NSHeight(container_bounds)) / 100, | 57 EXPECT_EQ((expected_height * NSHeight(container_bounds)) / 100, |
57 NSHeight(preview_frame)); | 58 NSHeight(preview_frame)); |
58 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(preview_frame)); | 59 EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(preview_frame)); |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
62 protected: | 63 protected: |
63 InstantModel instant_model_; | 64 InstantModel instant_model_; |
64 scoped_ptr<content::WebContents> web_contents_; | 65 scoped_ptr<content::WebContents> web_contents_; |
65 scoped_nsobject<PreviewableContentsController> controller_; | 66 scoped_nsobject<PreviewableContentsController> controller_; |
66 }; | 67 }; |
67 | 68 |
68 // Verify that the view is correctly laid out when size is specified in percent. | 69 // Verify that the view is correctly laid out when size is specified in percent. |
69 IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, SizePerecent) { | 70 IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, SizePerecent) { |
70 chrome::search::Mode mode; | 71 chrome::search::Mode mode; |
71 mode.mode = chrome::search::Mode::MODE_NTP; | 72 mode.mode = chrome::search::Mode::MODE_NTP; |
72 CGFloat expected_height = 30; | 73 CGFloat expected_height = 30; |
73 InstantSizeUnits units = INSTANT_SIZE_PERCENT; | 74 InstantSizeUnits units = INSTANT_SIZE_PERCENT; |
74 instant_model_.SetPreviewState(mode, expected_height, units); | 75 instant_model_.SetPreviewState(mode, expected_height, units); |
75 | 76 |
76 EXPECT_NSEQ([web_contents_->GetNativeView() superview], | 77 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], |
77 [controller_ view]); | 78 [controller_ view]); |
78 VerifyPreviewFrame(expected_height, units); | 79 VerifyPreviewFrame(expected_height, units); |
79 | 80 |
80 // Resize the view and verify that the preview is also resized. | 81 // Resize the view and verify that the preview is also resized. |
81 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; | 82 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; |
82 VerifyPreviewFrame(expected_height, units); | 83 VerifyPreviewFrame(expected_height, units); |
83 } | 84 } |
84 | 85 |
85 // Verify that the view is correctly laid out when size is specified in pixels. | 86 // Verify that the view is correctly laid out when size is specified in pixels. |
86 IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, SizePixels) { | 87 IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, SizePixels) { |
87 chrome::search::Mode mode; | 88 chrome::search::Mode mode; |
88 mode.mode = chrome::search::Mode::MODE_NTP; | 89 mode.mode = chrome::search::Mode::MODE_NTP; |
89 CGFloat expected_height = 30; | 90 CGFloat expected_height = 30; |
90 InstantSizeUnits units = INSTANT_SIZE_PIXELS; | 91 InstantSizeUnits units = INSTANT_SIZE_PIXELS; |
91 instant_model_.SetPreviewState(mode, expected_height, units); | 92 instant_model_.SetPreviewState(mode, expected_height, units); |
92 | 93 |
93 EXPECT_NSEQ([web_contents_->GetNativeView() superview], | 94 EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], |
94 [controller_ view]); | 95 [controller_ view]); |
95 VerifyPreviewFrame(expected_height, units); | 96 VerifyPreviewFrame(expected_height, units); |
96 | 97 |
97 // Resize the view and verify that the preview is also resized. | 98 // Resize the view and verify that the preview is also resized. |
98 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; | 99 [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; |
99 VerifyPreviewFrame(expected_height, units); | 100 VerifyPreviewFrame(expected_height, units); |
100 } | 101 } |
101 | 102 |
102 // Verify that a shadow is not shown when the preview covers the entire page | 103 // Verify that a shadow is not shown when the preview covers the entire page |
103 // or when the preview is in NTP mode. | 104 // or when the preview is in NTP mode. |
(...skipping 29 matching lines...) Expand all Loading... |
133 // Verify that the shadow is hidden when hiding the preview. | 134 // Verify that the shadow is hidden when hiding the preview. |
134 IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, HideShadow) { | 135 IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, HideShadow) { |
135 chrome::search::Mode mode; | 136 chrome::search::Mode mode; |
136 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; | 137 mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; |
137 instant_model_.SetPreviewState(mode, 10, INSTANT_SIZE_PERCENT); | 138 instant_model_.SetPreviewState(mode, 10, INSTANT_SIZE_PERCENT); |
138 EXPECT_TRUE([controller_ dropShadowView]); | 139 EXPECT_TRUE([controller_ dropShadowView]); |
139 | 140 |
140 [controller_ onActivateTabWithContents:web_contents_.get()]; | 141 [controller_ onActivateTabWithContents:web_contents_.get()]; |
141 EXPECT_FALSE([controller_ dropShadowView]); | 142 EXPECT_FALSE([controller_ dropShadowView]); |
142 } | 143 } |
OLD | NEW |