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

Side by Side Diff: chrome/browser/cocoa/reload_button_unittest.mm

Issue 2973004: [Mac]Implement ViewID support. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Turns out that, it's not a good solution. Created 10 years, 5 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
« no previous file with comments | « chrome/browser/cocoa/reload_button.mm ('k') | chrome/browser/cocoa/side_tab_strip_view.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/cocoa/reload_button.h" 7 #import "chrome/browser/cocoa/reload_button.h"
8 8
9 #include "base/scoped_nsobject.h" 9 #include "base/scoped_nsobject.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
(...skipping 11 matching lines...) Expand all
22 22
23 class ReloadButtonTest : public CocoaTest { 23 class ReloadButtonTest : public CocoaTest {
24 public: 24 public:
25 ReloadButtonTest() { 25 ReloadButtonTest() {
26 NSRect frame = NSMakeRect(0, 0, 20, 20); 26 NSRect frame = NSMakeRect(0, 0, 20, 20);
27 scoped_nsobject<ReloadButton> button( 27 scoped_nsobject<ReloadButton> button(
28 [[ReloadButton alloc] initWithFrame:frame]); 28 [[ReloadButton alloc] initWithFrame:frame]);
29 button_ = button.get(); 29 button_ = button.get();
30 30
31 // Set things up so unit tests have a reliable baseline. 31 // Set things up so unit tests have a reliable baseline.
32 [button_ setTag:IDC_RELOAD]; 32 [button_ setCommand:IDC_RELOAD];
33 [button_ awakeFromNib]; 33 [button_ awakeFromNib];
34 34
35 [[test_window() contentView] addSubview:button_]; 35 [[test_window() contentView] addSubview:button_];
36 } 36 }
37 37
38 ReloadButton* button_; 38 ReloadButton* button_;
39 }; 39 };
40 40
41 TEST_VIEW(ReloadButtonTest, button_) 41 TEST_VIEW(ReloadButtonTest, button_)
42 42
(...skipping 26 matching lines...) Expand all
69 [NSApp postEvent:click_two.second atStart:YES]; 69 [NSApp postEvent:click_two.second atStart:YES];
70 [button_ mouseDown:click_two.first]; 70 [button_ mouseDown:click_two.first];
71 71
72 [button_ setTarget:nil]; 72 [button_ setTarget:nil];
73 } 73 }
74 74
75 // Test that when forcing the mode, it takes effect immediately, 75 // Test that when forcing the mode, it takes effect immediately,
76 // regardless of whether the mouse is hovering. 76 // regardless of whether the mouse is hovering.
77 TEST_F(ReloadButtonTest, SetIsLoadingForce) { 77 TEST_F(ReloadButtonTest, SetIsLoadingForce) {
78 EXPECT_FALSE([button_ isMouseInside]); 78 EXPECT_FALSE([button_ isMouseInside]);
79 EXPECT_EQ([button_ tag], IDC_RELOAD); 79 EXPECT_EQ([button_ command], IDC_RELOAD);
80 80
81 // Changes to stop immediately. 81 // Changes to stop immediately.
82 [button_ setIsLoading:YES force:YES]; 82 [button_ setIsLoading:YES force:YES];
83 EXPECT_EQ([button_ tag], IDC_STOP); 83 EXPECT_EQ([button_ command], IDC_STOP);
84 84
85 // Changes to reload immediately. 85 // Changes to reload immediately.
86 [button_ setIsLoading:NO force:YES]; 86 [button_ setIsLoading:NO force:YES];
87 EXPECT_EQ([button_ tag], IDC_RELOAD); 87 EXPECT_EQ([button_ command], IDC_RELOAD);
88 88
89 // Changes to stop immediately when the mouse is hovered, and 89 // Changes to stop immediately when the mouse is hovered, and
90 // doesn't change when the mouse exits. 90 // doesn't change when the mouse exits.
91 [button_ mouseEntered:nil]; 91 [button_ mouseEntered:nil];
92 EXPECT_TRUE([button_ isMouseInside]); 92 EXPECT_TRUE([button_ isMouseInside]);
93 [button_ setIsLoading:YES force:YES]; 93 [button_ setIsLoading:YES force:YES];
94 EXPECT_EQ([button_ tag], IDC_STOP); 94 EXPECT_EQ([button_ command], IDC_STOP);
95 [button_ mouseExited:nil]; 95 [button_ mouseExited:nil];
96 EXPECT_FALSE([button_ isMouseInside]); 96 EXPECT_FALSE([button_ isMouseInside]);
97 EXPECT_EQ([button_ tag], IDC_STOP); 97 EXPECT_EQ([button_ command], IDC_STOP);
98 98
99 // Changes to reload immediately when the mouse is hovered, and 99 // Changes to reload immediately when the mouse is hovered, and
100 // doesn't change when the mouse exits. 100 // doesn't change when the mouse exits.
101 [button_ mouseEntered:nil]; 101 [button_ mouseEntered:nil];
102 EXPECT_TRUE([button_ isMouseInside]); 102 EXPECT_TRUE([button_ isMouseInside]);
103 [button_ setIsLoading:NO force:YES]; 103 [button_ setIsLoading:NO force:YES];
104 EXPECT_EQ([button_ tag], IDC_RELOAD); 104 EXPECT_EQ([button_ command], IDC_RELOAD);
105 [button_ mouseExited:nil]; 105 [button_ mouseExited:nil];
106 EXPECT_FALSE([button_ isMouseInside]); 106 EXPECT_FALSE([button_ isMouseInside]);
107 EXPECT_EQ([button_ tag], IDC_RELOAD); 107 EXPECT_EQ([button_ command], IDC_RELOAD);
108 } 108 }
109 109
110 // Test that without force, stop mode is set immediately, but reload 110 // Test that without force, stop mode is set immediately, but reload
111 // is affected by the hover status. 111 // is affected by the hover status.
112 TEST_F(ReloadButtonTest, SetIsLoadingNoForce) { 112 TEST_F(ReloadButtonTest, SetIsLoadingNoForce) {
113 EXPECT_FALSE([button_ isMouseInside]); 113 EXPECT_FALSE([button_ isMouseInside]);
114 EXPECT_EQ([button_ tag], IDC_RELOAD); 114 EXPECT_EQ([button_ command], IDC_RELOAD);
115 115
116 // Changes to stop immediately when the mouse is not hovering. 116 // Changes to stop immediately when the mouse is not hovering.
117 [button_ setIsLoading:YES force:NO]; 117 [button_ setIsLoading:YES force:NO];
118 EXPECT_EQ([button_ tag], IDC_STOP); 118 EXPECT_EQ([button_ command], IDC_STOP);
119 119
120 // Changes to reload immediately when the mouse is not hovering. 120 // Changes to reload immediately when the mouse is not hovering.
121 [button_ setIsLoading:NO force:NO]; 121 [button_ setIsLoading:NO force:NO];
122 EXPECT_EQ([button_ tag], IDC_RELOAD); 122 EXPECT_EQ([button_ command], IDC_RELOAD);
123 123
124 // Changes to stop immediately when the mouse is hovered, and 124 // Changes to stop immediately when the mouse is hovered, and
125 // doesn't change when the mouse exits. 125 // doesn't change when the mouse exits.
126 [button_ mouseEntered:nil]; 126 [button_ mouseEntered:nil];
127 EXPECT_TRUE([button_ isMouseInside]); 127 EXPECT_TRUE([button_ isMouseInside]);
128 [button_ setIsLoading:YES force:NO]; 128 [button_ setIsLoading:YES force:NO];
129 EXPECT_EQ([button_ tag], IDC_STOP); 129 EXPECT_EQ([button_ command], IDC_STOP);
130 [button_ mouseExited:nil]; 130 [button_ mouseExited:nil];
131 EXPECT_FALSE([button_ isMouseInside]); 131 EXPECT_FALSE([button_ isMouseInside]);
132 EXPECT_EQ([button_ tag], IDC_STOP); 132 EXPECT_EQ([button_ command], IDC_STOP);
133 133
134 // Does not change to reload immediately when the mouse is hovered, 134 // Does not change to reload immediately when the mouse is hovered,
135 // changes when the mouse exits. 135 // changes when the mouse exits.
136 [button_ mouseEntered:nil]; 136 [button_ mouseEntered:nil];
137 EXPECT_TRUE([button_ isMouseInside]); 137 EXPECT_TRUE([button_ isMouseInside]);
138 [button_ setIsLoading:NO force:NO]; 138 [button_ setIsLoading:NO force:NO];
139 EXPECT_EQ([button_ tag], IDC_STOP); 139 EXPECT_EQ([button_ command], IDC_STOP);
140 [button_ mouseExited:nil]; 140 [button_ mouseExited:nil];
141 EXPECT_FALSE([button_ isMouseInside]); 141 EXPECT_FALSE([button_ isMouseInside]);
142 EXPECT_EQ([button_ tag], IDC_RELOAD); 142 EXPECT_EQ([button_ command], IDC_RELOAD);
143 } 143 }
144 144
145 // Test that pressing stop after reload mode has been requested 145 // Test that pressing stop after reload mode has been requested
146 // doesn't forward the stop message. 146 // doesn't forward the stop message.
147 TEST_F(ReloadButtonTest, StopAfterReloadSet) { 147 TEST_F(ReloadButtonTest, StopAfterReloadSet) {
148 id mock_target = [OCMockObject mockForProtocol:@protocol(TargetActionMock)]; 148 id mock_target = [OCMockObject mockForProtocol:@protocol(TargetActionMock)];
149 [button_ setTarget:mock_target]; 149 [button_ setTarget:mock_target];
150 [button_ setAction:@selector(anAction:)]; 150 [button_ setAction:@selector(anAction:)];
151 151
152 EXPECT_FALSE([button_ isMouseInside]); 152 EXPECT_FALSE([button_ isMouseInside]);
153 153
154 // Get to stop mode. 154 // Get to stop mode.
155 [button_ setIsLoading:YES force:YES]; 155 [button_ setIsLoading:YES force:YES];
156 EXPECT_EQ([button_ tag], IDC_STOP); 156 EXPECT_EQ([button_ command], IDC_STOP);
157 157
158 // Expect the action once. 158 // Expect the action once.
159 [[mock_target expect] anAction:button_]; 159 [[mock_target expect] anAction:button_];
160 160
161 // Clicking in stop mode should send the action and transition to 161 // Clicking in stop mode should send the action and transition to
162 // reload mode. 162 // reload mode.
163 const std::pair<NSEvent*,NSEvent*> click = 163 const std::pair<NSEvent*,NSEvent*> click =
164 test_event_utils::MouseClickInView(button_, 1); 164 test_event_utils::MouseClickInView(button_, 1);
165 [NSApp postEvent:click.second atStart:YES]; 165 [NSApp postEvent:click.second atStart:YES];
166 [button_ mouseDown:click.first]; 166 [button_ mouseDown:click.first];
167 EXPECT_EQ([button_ tag], IDC_RELOAD); 167 EXPECT_EQ([button_ command], IDC_RELOAD);
168 168
169 // Get back to stop mode. 169 // Get back to stop mode.
170 [button_ setIsLoading:YES force:YES]; 170 [button_ setIsLoading:YES force:YES];
171 EXPECT_EQ([button_ tag], IDC_STOP); 171 EXPECT_EQ([button_ command], IDC_STOP);
172 172
173 // If hover prevented reload mode immediately taking effect, clicks 173 // If hover prevented reload mode immediately taking effect, clicks
174 // should not send any action, but should still transition to reload 174 // should not send any action, but should still transition to reload
175 // mode. 175 // mode.
176 [button_ mouseEntered:nil]; 176 [button_ mouseEntered:nil];
177 EXPECT_TRUE([button_ isMouseInside]); 177 EXPECT_TRUE([button_ isMouseInside]);
178 [button_ setIsLoading:NO force:NO]; 178 [button_ setIsLoading:NO force:NO];
179 EXPECT_EQ([button_ tag], IDC_STOP); 179 EXPECT_EQ([button_ command], IDC_STOP);
180 [NSApp postEvent:click.second atStart:YES]; 180 [NSApp postEvent:click.second atStart:YES];
181 [button_ mouseDown:click.first]; 181 [button_ mouseDown:click.first];
182 EXPECT_EQ([button_ tag], IDC_RELOAD); 182 EXPECT_EQ([button_ command], IDC_RELOAD);
183 183
184 [button_ setTarget:nil]; 184 [button_ setTarget:nil];
185 } 185 }
186 186
187 } // namespace 187 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/reload_button.mm ('k') | chrome/browser/cocoa/side_tab_strip_view.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698