OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_test_helper.h" |
10 #import "chrome/browser/ui/cocoa/bubble_view.h" | 11 #import "chrome/browser/ui/cocoa/bubble_view.h" |
11 #import "chrome/browser/ui/cocoa/browser_test_helper.h" | |
12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
13 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 13 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #import "testing/gtest_mac.h" | 16 #import "testing/gtest_mac.h" |
17 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
18 | 18 |
19 // The test delegate records all of the status bubble object's state | 19 // The test delegate records all of the status bubble object's state |
20 // transitions. | 20 // transitions. |
21 @interface StatusBubbleMacTestDelegate : NSObject { | 21 @interface StatusBubbleMacTestDelegate : NSObject { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Set the status to the exact same thing again | 184 // Set the status to the exact same thing again |
185 bubble_->SetStatus(UTF8ToUTF16("This is a test")); | 185 bubble_->SetStatus(UTF8ToUTF16("This is a test")); |
186 EXPECT_NSEQ(@"This is a test", GetText()); | 186 EXPECT_NSEQ(@"This is a test", GetText()); |
187 | 187 |
188 // Hide it | 188 // Hide it |
189 bubble_->SetStatus(string16()); | 189 bubble_->SetStatus(string16()); |
190 EXPECT_FALSE(IsVisible()); | 190 EXPECT_FALSE(IsVisible()); |
191 } | 191 } |
192 | 192 |
193 TEST_F(StatusBubbleMacTest, SetURL) { | 193 TEST_F(StatusBubbleMacTest, SetURL) { |
194 bubble_->SetURL(GURL(), string16()); | 194 bubble_->SetURL(GURL(), std::string()); |
195 EXPECT_FALSE(IsVisible()); | 195 EXPECT_FALSE(IsVisible()); |
196 bubble_->SetURL(GURL("bad url"), string16()); | 196 bubble_->SetURL(GURL("bad url"), std::string()); |
197 EXPECT_FALSE(IsVisible()); | 197 EXPECT_FALSE(IsVisible()); |
198 bubble_->SetURL(GURL("http://"), string16()); | 198 bubble_->SetURL(GURL("http://"), std::string()); |
199 EXPECT_TRUE(IsVisible()); | 199 EXPECT_TRUE(IsVisible()); |
200 EXPECT_NSEQ(@"http:", GetURLText()); | 200 EXPECT_NSEQ(@"http:", GetURLText()); |
201 bubble_->SetURL(GURL("about:blank"), string16()); | 201 bubble_->SetURL(GURL("about:blank"), std::string()); |
202 EXPECT_TRUE(IsVisible()); | 202 EXPECT_TRUE(IsVisible()); |
203 EXPECT_NSEQ(@"about:blank", GetURLText()); | 203 EXPECT_NSEQ(@"about:blank", GetURLText()); |
204 bubble_->SetURL(GURL("foopy://"), string16()); | 204 bubble_->SetURL(GURL("foopy://"), std::string()); |
205 EXPECT_TRUE(IsVisible()); | 205 EXPECT_TRUE(IsVisible()); |
206 EXPECT_NSEQ(@"foopy://", GetURLText()); | 206 EXPECT_NSEQ(@"foopy://", GetURLText()); |
207 bubble_->SetURL(GURL("http://www.cnn.com"), string16()); | 207 bubble_->SetURL(GURL("http://www.cnn.com"), std::string()); |
208 EXPECT_TRUE(IsVisible()); | 208 EXPECT_TRUE(IsVisible()); |
209 EXPECT_NSEQ(@"www.cnn.com", GetURLText()); | 209 EXPECT_NSEQ(@"www.cnn.com", GetURLText()); |
210 } | 210 } |
211 | 211 |
212 // Test hiding bubble that's already hidden. | 212 // Test hiding bubble that's already hidden. |
213 TEST_F(StatusBubbleMacTest, Hides) { | 213 TEST_F(StatusBubbleMacTest, Hides) { |
214 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 214 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
215 EXPECT_TRUE(IsVisible()); | 215 EXPECT_TRUE(IsVisible()); |
216 bubble_->Hide(); | 216 bubble_->Hide(); |
217 EXPECT_FALSE(IsVisible()); | 217 EXPECT_FALSE(IsVisible()); |
218 bubble_->Hide(); | 218 bubble_->Hide(); |
219 EXPECT_FALSE(IsVisible()); | 219 EXPECT_FALSE(IsVisible()); |
220 } | 220 } |
221 | 221 |
222 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText(). | 222 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText(). |
223 TEST_F(StatusBubbleMacTest, SetStatusAndURL) { | 223 TEST_F(StatusBubbleMacTest, SetStatusAndURL) { |
224 EXPECT_FALSE(IsVisible()); | 224 EXPECT_FALSE(IsVisible()); |
225 bubble_->SetStatus(UTF8ToUTF16("Status")); | 225 bubble_->SetStatus(UTF8ToUTF16("Status")); |
226 EXPECT_TRUE(IsVisible()); | 226 EXPECT_TRUE(IsVisible()); |
227 EXPECT_NSEQ(@"Status", GetBubbleViewText()); | 227 EXPECT_NSEQ(@"Status", GetBubbleViewText()); |
228 bubble_->SetURL(GURL("http://www.nytimes.com"), string16()); | 228 bubble_->SetURL(GURL("http://www.nytimes.com"), std::string()); |
229 EXPECT_TRUE(IsVisible()); | 229 EXPECT_TRUE(IsVisible()); |
230 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); | 230 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); |
231 bubble_->SetURL(GURL(), string16()); | 231 bubble_->SetURL(GURL(), std::string()); |
232 EXPECT_TRUE(IsVisible()); | 232 EXPECT_TRUE(IsVisible()); |
233 EXPECT_NSEQ(@"Status", GetBubbleViewText()); | 233 EXPECT_NSEQ(@"Status", GetBubbleViewText()); |
234 bubble_->SetStatus(string16()); | 234 bubble_->SetStatus(string16()); |
235 EXPECT_FALSE(IsVisible()); | 235 EXPECT_FALSE(IsVisible()); |
236 bubble_->SetURL(GURL("http://www.nytimes.com"), string16()); | 236 bubble_->SetURL(GURL("http://www.nytimes.com"), std::string()); |
237 EXPECT_TRUE(IsVisible()); | 237 EXPECT_TRUE(IsVisible()); |
238 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); | 238 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); |
239 bubble_->SetStatus(UTF8ToUTF16("Status")); | 239 bubble_->SetStatus(UTF8ToUTF16("Status")); |
240 EXPECT_TRUE(IsVisible()); | 240 EXPECT_TRUE(IsVisible()); |
241 EXPECT_NSEQ(@"Status", GetBubbleViewText()); | 241 EXPECT_NSEQ(@"Status", GetBubbleViewText()); |
242 bubble_->SetStatus(string16()); | 242 bubble_->SetStatus(string16()); |
243 EXPECT_TRUE(IsVisible()); | 243 EXPECT_TRUE(IsVisible()); |
244 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); | 244 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); |
245 bubble_->SetURL(GURL(), string16()); | 245 bubble_->SetURL(GURL(), std::string()); |
246 EXPECT_FALSE(IsVisible()); | 246 EXPECT_FALSE(IsVisible()); |
247 } | 247 } |
248 | 248 |
249 // Test that the status bubble goes through the correct delay and fade states. | 249 // Test that the status bubble goes through the correct delay and fade states. |
250 // The delay and fade duration are simulated and not actually experienced | 250 // The delay and fade duration are simulated and not actually experienced |
251 // during the test because StatusBubbleMacTest sets immediate_ mode. | 251 // during the test because StatusBubbleMacTest sets immediate_ mode. |
252 TEST_F(StatusBubbleMacTest, StateTransitions) { | 252 TEST_F(StatusBubbleMacTest, StateTransitions) { |
253 // First, some sanity | 253 // First, some sanity |
254 | 254 |
255 EXPECT_FALSE(IsVisible()); | 255 EXPECT_FALSE(IsVisible()); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 NSWindow* window = test_window(); | 575 NSWindow* window = test_window(); |
576 ASSERT_TRUE(window); | 576 ASSERT_TRUE(window); |
577 NSRect window_frame = [window frame]; | 577 NSRect window_frame = [window frame]; |
578 window_frame.size.width = 600.0; | 578 window_frame.size.width = 600.0; |
579 [window setFrame:window_frame display:YES]; | 579 [window setFrame:window_frame display:YES]; |
580 | 580 |
581 // Check basic expansion | 581 // Check basic expansion |
582 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 582 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
583 EXPECT_TRUE(IsVisible()); | 583 EXPECT_TRUE(IsVisible()); |
584 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html"), | 584 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html"), |
585 string16()); | 585 std::string()); |
586 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 586 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
587 bubble_->ExpandBubble(); | 587 bubble_->ExpandBubble(); |
588 EXPECT_TRUE(IsVisible()); | 588 EXPECT_TRUE(IsVisible()); |
589 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); | 589 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); |
590 bubble_->Hide(); | 590 bubble_->Hide(); |
591 | 591 |
592 // Make sure bubble resets after hide. | 592 // Make sure bubble resets after hide. |
593 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 593 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
594 bubble_->SetURL(GURL("http://www.snickersnee.com/pioneer_fishstix.html"), | 594 bubble_->SetURL(GURL("http://www.snickersnee.com/pioneer_fishstix.html"), |
595 string16()); | 595 std::string()); |
596 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 596 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
597 // ...and that it expands again properly. | 597 // ...and that it expands again properly. |
598 bubble_->ExpandBubble(); | 598 bubble_->ExpandBubble(); |
599 EXPECT_NSEQ(@"www.snickersnee.com/pioneer_fishstix.html", GetURLText()); | 599 EXPECT_NSEQ(@"www.snickersnee.com/pioneer_fishstix.html", GetURLText()); |
600 // ...again, again! | 600 // ...again, again! |
601 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html"), | 601 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html"), |
602 string16()); | 602 std::string()); |
603 bubble_->ExpandBubble(); | 603 bubble_->ExpandBubble(); |
604 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); | 604 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); |
605 bubble_->Hide(); | 605 bubble_->Hide(); |
606 | 606 |
607 window_frame = [window frame]; | 607 window_frame = [window frame]; |
608 window_frame.size.width = 300.0; | 608 window_frame.size.width = 300.0; |
609 [window setFrame:window_frame display:YES]; | 609 [window setFrame:window_frame display:YES]; |
610 | 610 |
611 // Very long URL's will be cut off even in the expanded state. | 611 // Very long URL's will be cut off even in the expanded state. |
612 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 612 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
613 const char veryLongUrl[] = | 613 const char veryLongUrl[] = |
614 "http://www.diewahrscheinlichlaengstepralinederwelt.com/duuuuplo.html"; | 614 "http://www.diewahrscheinlichlaengstepralinederwelt.com/duuuuplo.html"; |
615 bubble_->SetURL(GURL(veryLongUrl), string16()); | 615 bubble_->SetURL(GURL(veryLongUrl), std::string()); |
616 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 616 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
617 bubble_->ExpandBubble(); | 617 bubble_->ExpandBubble(); |
618 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 618 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
619 } | 619 } |
620 | 620 |
621 TEST_F(StatusBubbleMacTest, BubbleAvoidsMouse) { | 621 TEST_F(StatusBubbleMacTest, BubbleAvoidsMouse) { |
622 NSWindow* window = test_window(); | 622 NSWindow* window = test_window(); |
623 | 623 |
624 // All coordinates here are relative to the window origin. | 624 // All coordinates here are relative to the window origin. |
625 | 625 |
(...skipping 24 matching lines...) Expand all Loading... |
650 int windowWidth = NSWidth([window frame]); | 650 int windowWidth = NSWidth([window frame]); |
651 for (int x = 0; x < windowWidth; x += smallValue) { | 651 for (int x = 0; x < windowWidth; x += smallValue) { |
652 ASSERT_TRUE(CheckAvoidsMouse(x, smallValue)); | 652 ASSERT_TRUE(CheckAvoidsMouse(x, smallValue)); |
653 } | 653 } |
654 | 654 |
655 // Simulate moving the mouse from right to left. | 655 // Simulate moving the mouse from right to left. |
656 for (int x = windowWidth; x >= 0; x -= smallValue) { | 656 for (int x = windowWidth; x >= 0; x -= smallValue) { |
657 ASSERT_TRUE(CheckAvoidsMouse(x, smallValue)); | 657 ASSERT_TRUE(CheckAvoidsMouse(x, smallValue)); |
658 } | 658 } |
659 } | 659 } |
OLD | NEW |