OLD | NEW |
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 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 5 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
6 | 6 |
7 #include "chrome/browser/devtools/devtools_window.h" | 7 #include "chrome/browser/devtools/devtools_window.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
13 | 14 |
14 class DevToolsControllerTest : public InProcessBrowserTest { | 15 class DevToolsControllerTest : public InProcessBrowserTest { |
15 public: | 16 public: |
16 DevToolsControllerTest() : InProcessBrowserTest() { | 17 DevToolsControllerTest() : InProcessBrowserTest() { |
17 } | 18 } |
18 | 19 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 64 |
64 // When docked to the right the dev tools view should be shrunk so that it | 65 // When docked to the right the dev tools view should be shrunk so that it |
65 // doesn't overlap the bookmark bar. | 66 // doesn't overlap the bookmark bar. |
66 IN_PROC_BROWSER_TEST_F(DevToolsControllerTest, ViewSize) { | 67 IN_PROC_BROWSER_TEST_F(DevToolsControllerTest, ViewSize) { |
67 EXPECT_EQ(2u, [[[controller() splitView] subviews] count]); | 68 EXPECT_EQ(2u, [[[controller() splitView] subviews] count]); |
68 NSView* container_view = [[[controller() splitView] subviews] lastObject]; | 69 NSView* container_view = [[[controller() splitView] subviews] lastObject]; |
69 EXPECT_EQ(1u, [[container_view subviews] count]); | 70 EXPECT_EQ(1u, [[container_view subviews] count]); |
70 NSView* dev_tools_view = [[container_view subviews] lastObject]; | 71 NSView* dev_tools_view = [[container_view subviews] lastObject]; |
71 CGFloat width = NSWidth([[controller() splitView] bounds]); | 72 CGFloat width = NSWidth([[controller() splitView] bounds]); |
72 CGFloat height = NSHeight([[controller() splitView] bounds]); | 73 CGFloat height = NSHeight([[controller() splitView] bounds]); |
73 | 74 CGFloat offset = [controller() topContentOffset]; |
74 SetDockSide(DEVTOOLS_DOCK_SIDE_BOTTOM); | |
75 EXPECT_EQ(width, NSWidth([dev_tools_view bounds])); | |
76 | |
77 SetDockSide(DEVTOOLS_DOCK_SIDE_RIGHT); | |
78 EXPECT_EQ(height, NSHeight([dev_tools_view bounds])); | |
79 | |
80 CGFloat offset = 50; | |
81 [controller() setTopContentOffset:offset]; | |
82 | 75 |
83 SetDockSide(DEVTOOLS_DOCK_SIDE_BOTTOM); | 76 SetDockSide(DEVTOOLS_DOCK_SIDE_BOTTOM); |
84 EXPECT_EQ(width, NSWidth([dev_tools_view bounds])); | 77 EXPECT_EQ(width, NSWidth([dev_tools_view bounds])); |
85 | 78 |
86 SetDockSide(DEVTOOLS_DOCK_SIDE_RIGHT); | 79 SetDockSide(DEVTOOLS_DOCK_SIDE_RIGHT); |
87 EXPECT_EQ(height - offset, NSHeight([dev_tools_view bounds])); | 80 EXPECT_EQ(height - offset, NSHeight([dev_tools_view bounds])); |
| 81 |
| 82 CGFloat new_offset = 50; |
| 83 [controller() setTopContentOffset:new_offset]; |
| 84 |
| 85 SetDockSide(DEVTOOLS_DOCK_SIDE_BOTTOM); |
| 86 EXPECT_EQ(width, NSWidth([dev_tools_view bounds])); |
| 87 |
| 88 SetDockSide(DEVTOOLS_DOCK_SIDE_RIGHT); |
| 89 EXPECT_EQ(height - new_offset, NSHeight([dev_tools_view bounds])); |
88 } | 90 } |
89 | 91 |
90 // Verify that the dev tool's web view is layed out correctly when docked to the | 92 // Verify that the dev tool's web view is layed out correctly when docked to the |
91 // right. | 93 // right. |
92 IN_PROC_BROWSER_TEST_F(DevToolsControllerTest, WebViewLayout) { | 94 IN_PROC_BROWSER_TEST_F(DevToolsControllerTest, WebViewLayout) { |
93 CGFloat offset = 50; | 95 CGFloat offset = 50; |
94 [controller() setTopContentOffset:offset]; | 96 [controller() setTopContentOffset:offset]; |
95 | 97 |
96 SetDockSide(DEVTOOLS_DOCK_SIDE_RIGHT); | 98 SetDockSide(DEVTOOLS_DOCK_SIDE_RIGHT); |
97 AddTabAtIndex(0, | 99 AddTabAtIndex(0, |
98 GURL(chrome::kAboutBlankURL), | 100 GURL(chrome::kAboutBlankURL), |
99 content::PAGE_TRANSITION_TYPED); | 101 content::PAGE_TRANSITION_TYPED); |
100 DevToolsWindow::ToggleDevToolsWindow(browser(), DEVTOOLS_TOGGLE_ACTION_SHOW); | 102 DevToolsWindow::ToggleDevToolsWindow(browser(), DEVTOOLS_TOGGLE_ACTION_SHOW); |
101 | 103 |
102 NSView* container_view = [[[controller() splitView] subviews] lastObject]; | 104 NSView* container_view = [[[controller() splitView] subviews] lastObject]; |
103 NSView* dev_tools_view = [[container_view subviews] lastObject]; | 105 NSView* dev_tools_view = [[container_view subviews] lastObject]; |
104 NSView* web_view = [[dev_tools_view subviews] lastObject]; | 106 NSView* web_view = [[dev_tools_view subviews] lastObject]; |
105 | 107 |
106 CGFloat height = NSHeight([[controller() splitView] bounds]); | 108 CGFloat height = NSHeight([[controller() splitView] bounds]); |
107 | 109 |
108 EXPECT_EQ(height - offset, NSHeight([web_view bounds])); | 110 EXPECT_EQ(height - offset, NSHeight([web_view bounds])); |
109 EXPECT_EQ(0, NSMinY([web_view bounds])); | 111 EXPECT_EQ(0, NSMinY([web_view bounds])); |
110 | 112 |
111 // Update the offset and verify that the view is resized. | 113 // Update the offset and verify that the view is resized. |
112 CGFloat new_offset = 25; | 114 CGFloat new_offset = 25; |
113 [controller() setTopContentOffset:new_offset]; | 115 [controller() setTopContentOffset:new_offset]; |
114 EXPECT_EQ(height - new_offset, NSHeight([web_view bounds])); | 116 EXPECT_EQ(height - new_offset, NSHeight([web_view bounds])); |
115 EXPECT_EQ(0, NSMinY([web_view bounds])); | 117 EXPECT_EQ(0, NSMinY([web_view bounds])); |
116 } | 118 } |
| 119 |
| 120 // Verify that the dev tools undocked window is layed out correctly. |
| 121 IN_PROC_BROWSER_TEST_F(DevToolsControllerTest, UndockedOffset) { |
| 122 BrowserList* browser_list = |
| 123 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 124 EXPECT_EQ(1u, browser_list->size()); |
| 125 SetDockSide(DEVTOOLS_DOCK_SIDE_UNDOCKED); |
| 126 EXPECT_EQ(2u, browser_list->size()); |
| 127 |
| 128 Browser* dev_tools_browser = browser_list->get(1); |
| 129 BrowserWindowController* window_controller = |
| 130 [BrowserWindowController browserWindowControllerForWindow: |
| 131 dev_tools_browser->window()->GetNativeWindow()]; |
| 132 EXPECT_EQ(0.0, [[window_controller devToolsController] topContentOffset]); |
| 133 } |
OLD | NEW |