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/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // Set the status to the exact same thing again | 186 // Set the status to the exact same thing again |
187 bubble_->SetStatus(UTF8ToUTF16("This is a test")); | 187 bubble_->SetStatus(UTF8ToUTF16("This is a test")); |
188 EXPECT_NSEQ(@"This is a test", GetText()); | 188 EXPECT_NSEQ(@"This is a test", GetText()); |
189 | 189 |
190 // Hide it | 190 // Hide it |
191 bubble_->SetStatus(base::string16()); | 191 bubble_->SetStatus(base::string16()); |
192 EXPECT_FALSE(IsVisible()); | 192 EXPECT_FALSE(IsVisible()); |
193 } | 193 } |
194 | 194 |
195 TEST_F(StatusBubbleMacTest, SetURL) { | 195 TEST_F(StatusBubbleMacTest, SetURL) { |
196 bubble_->SetURL(GURL(), std::string()); | 196 bubble_->SetURL(GURL()); |
197 EXPECT_FALSE(IsVisible()); | 197 EXPECT_FALSE(IsVisible()); |
198 bubble_->SetURL(GURL("bad url"), std::string()); | 198 bubble_->SetURL(GURL("bad url")); |
199 EXPECT_FALSE(IsVisible()); | 199 EXPECT_FALSE(IsVisible()); |
200 bubble_->SetURL(GURL("http://"), std::string()); | 200 bubble_->SetURL(GURL("http://")); |
201 EXPECT_TRUE(IsVisible()); | 201 EXPECT_TRUE(IsVisible()); |
202 EXPECT_NSEQ(@"http:", GetURLText()); | 202 EXPECT_NSEQ(@"http:", GetURLText()); |
203 bubble_->SetURL(GURL("about:blank"), std::string()); | 203 bubble_->SetURL(GURL("about:blank")); |
204 EXPECT_TRUE(IsVisible()); | 204 EXPECT_TRUE(IsVisible()); |
205 EXPECT_NSEQ(@"about:blank", GetURLText()); | 205 EXPECT_NSEQ(@"about:blank", GetURLText()); |
206 bubble_->SetURL(GURL("foopy://"), std::string()); | 206 bubble_->SetURL(GURL("foopy://")); |
207 EXPECT_TRUE(IsVisible()); | 207 EXPECT_TRUE(IsVisible()); |
208 EXPECT_NSEQ(@"foopy://", GetURLText()); | 208 EXPECT_NSEQ(@"foopy://", GetURLText()); |
209 bubble_->SetURL(GURL("http://www.cnn.com"), std::string()); | 209 bubble_->SetURL(GURL("http://www.cnn.com")); |
210 EXPECT_TRUE(IsVisible()); | 210 EXPECT_TRUE(IsVisible()); |
211 EXPECT_NSEQ(@"www.cnn.com", GetURLText()); | 211 EXPECT_NSEQ(@"www.cnn.com", GetURLText()); |
212 } | 212 } |
213 | 213 |
214 // Test hiding bubble that's already hidden. | 214 // Test hiding bubble that's already hidden. |
215 TEST_F(StatusBubbleMacTest, Hides) { | 215 TEST_F(StatusBubbleMacTest, Hides) { |
216 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 216 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
217 EXPECT_TRUE(IsVisible()); | 217 EXPECT_TRUE(IsVisible()); |
218 bubble_->Hide(); | 218 bubble_->Hide(); |
219 EXPECT_FALSE(IsVisible()); | 219 EXPECT_FALSE(IsVisible()); |
220 bubble_->Hide(); | 220 bubble_->Hide(); |
221 EXPECT_FALSE(IsVisible()); | 221 EXPECT_FALSE(IsVisible()); |
222 } | 222 } |
223 | 223 |
224 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText(). | 224 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText(). |
225 TEST_F(StatusBubbleMacTest, SetStatusAndURL) { | 225 TEST_F(StatusBubbleMacTest, SetStatusAndURL) { |
226 EXPECT_FALSE(IsVisible()); | 226 EXPECT_FALSE(IsVisible()); |
227 bubble_->SetStatus(UTF8ToUTF16("Status")); | 227 bubble_->SetStatus(UTF8ToUTF16("Status")); |
228 EXPECT_TRUE(IsVisible()); | 228 EXPECT_TRUE(IsVisible()); |
229 EXPECT_NSEQ(@"Status", GetBubbleViewText()); | 229 EXPECT_NSEQ(@"Status", GetBubbleViewText()); |
230 bubble_->SetURL(GURL("http://www.nytimes.com"), std::string()); | 230 bubble_->SetURL(GURL("http://www.nytimes.com")); |
231 EXPECT_TRUE(IsVisible()); | 231 EXPECT_TRUE(IsVisible()); |
232 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); | 232 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); |
233 bubble_->SetURL(GURL(), std::string()); | 233 bubble_->SetURL(GURL()); |
234 EXPECT_TRUE(IsVisible()); | 234 EXPECT_TRUE(IsVisible()); |
235 EXPECT_NSEQ(@"Status", GetBubbleViewText()); | 235 EXPECT_NSEQ(@"Status", GetBubbleViewText()); |
236 bubble_->SetStatus(base::string16()); | 236 bubble_->SetStatus(base::string16()); |
237 EXPECT_FALSE(IsVisible()); | 237 EXPECT_FALSE(IsVisible()); |
238 bubble_->SetURL(GURL("http://www.nytimes.com"), std::string()); | 238 bubble_->SetURL(GURL("http://www.nytimes.com")); |
239 EXPECT_TRUE(IsVisible()); | 239 EXPECT_TRUE(IsVisible()); |
240 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); | 240 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); |
241 bubble_->SetStatus(UTF8ToUTF16("Status")); | 241 bubble_->SetStatus(UTF8ToUTF16("Status")); |
242 EXPECT_TRUE(IsVisible()); | 242 EXPECT_TRUE(IsVisible()); |
243 EXPECT_NSEQ(@"Status", GetBubbleViewText()); | 243 EXPECT_NSEQ(@"Status", GetBubbleViewText()); |
244 bubble_->SetStatus(base::string16()); | 244 bubble_->SetStatus(base::string16()); |
245 EXPECT_TRUE(IsVisible()); | 245 EXPECT_TRUE(IsVisible()); |
246 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); | 246 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText()); |
247 bubble_->SetURL(GURL(), std::string()); | 247 bubble_->SetURL(GURL()); |
248 EXPECT_FALSE(IsVisible()); | 248 EXPECT_FALSE(IsVisible()); |
249 } | 249 } |
250 | 250 |
251 // Test that the status bubble goes through the correct delay and fade states. | 251 // Test that the status bubble goes through the correct delay and fade states. |
252 // The delay and fade duration are simulated and not actually experienced | 252 // The delay and fade duration are simulated and not actually experienced |
253 // during the test because StatusBubbleMacTest sets immediate_ mode. | 253 // during the test because StatusBubbleMacTest sets immediate_ mode. |
254 TEST_F(StatusBubbleMacTest, StateTransitions) { | 254 TEST_F(StatusBubbleMacTest, StateTransitions) { |
255 // First, some sanity | 255 // First, some sanity |
256 | 256 |
257 EXPECT_FALSE(IsVisible()); | 257 EXPECT_FALSE(IsVisible()); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 andReturn:[NSFont fontWithName:@"Lucida Grande" size:11]] font]; | 584 andReturn:[NSFont fontWithName:@"Lucida Grande" size:11]] font]; |
585 | 585 |
586 ASSERT_TRUE(window); | 586 ASSERT_TRUE(window); |
587 NSRect window_frame = [window frame]; | 587 NSRect window_frame = [window frame]; |
588 window_frame.size.width = 600.0; | 588 window_frame.size.width = 600.0; |
589 [window setFrame:window_frame display:YES]; | 589 [window setFrame:window_frame display:YES]; |
590 | 590 |
591 // Check basic expansion | 591 // Check basic expansion |
592 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 592 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
593 EXPECT_TRUE(IsVisible()); | 593 EXPECT_TRUE(IsVisible()); |
594 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html"), | 594 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html")); |
595 std::string()); | |
596 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 595 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
597 bubble_->ExpandBubble(); | 596 bubble_->ExpandBubble(); |
598 EXPECT_TRUE(IsVisible()); | 597 EXPECT_TRUE(IsVisible()); |
599 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); | 598 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); |
600 bubble_->Hide(); | 599 bubble_->Hide(); |
601 | 600 |
602 // Make sure bubble resets after hide. | 601 // Make sure bubble resets after hide. |
603 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 602 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
604 bubble_->SetURL(GURL("http://www.snickersnee.com/pioneer_fishstix.html"), | 603 bubble_->SetURL(GURL("http://www.snickersnee.com/pioneer_fishstix.html")); |
605 std::string()); | |
606 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 604 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
607 // ...and that it expands again properly. | 605 // ...and that it expands again properly. |
608 bubble_->ExpandBubble(); | 606 bubble_->ExpandBubble(); |
609 EXPECT_NSEQ(@"www.snickersnee.com/pioneer_fishstix.html", GetURLText()); | 607 EXPECT_NSEQ(@"www.snickersnee.com/pioneer_fishstix.html", GetURLText()); |
610 // ...again, again! | 608 // ...again, again! |
611 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html"), | 609 bubble_->SetURL(GURL("http://www.battersbox.com/peter_paul_and_mary.html")); |
612 std::string()); | |
613 bubble_->ExpandBubble(); | 610 bubble_->ExpandBubble(); |
614 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); | 611 EXPECT_NSEQ(@"www.battersbox.com/peter_paul_and_mary.html", GetURLText()); |
615 bubble_->Hide(); | 612 bubble_->Hide(); |
616 | 613 |
617 window_frame = [window frame]; | 614 window_frame = [window frame]; |
618 window_frame.size.width = 300.0; | 615 window_frame.size.width = 300.0; |
619 [window setFrame:window_frame display:YES]; | 616 [window setFrame:window_frame display:YES]; |
620 | 617 |
621 // Very long URL's will be cut off even in the expanded state. | 618 // Very long URL's will be cut off even in the expanded state. |
622 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 619 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
623 const char veryLongUrl[] = | 620 const char veryLongUrl[] = |
624 "http://www.diewahrscheinlichlaengstepralinederwelt.com/duuuuplo.html"; | 621 "http://www.diewahrscheinlichlaengstepralinederwelt.com/duuuuplo.html"; |
625 bubble_->SetURL(GURL(veryLongUrl), std::string()); | 622 bubble_->SetURL(GURL(veryLongUrl)); |
626 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 623 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
627 bubble_->ExpandBubble(); | 624 bubble_->ExpandBubble(); |
628 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); | 625 EXPECT_TRUE([GetURLText() hasSuffix:@"\u2026"]); |
629 } | 626 } |
630 | 627 |
631 TEST_F(StatusBubbleMacTest, BubbleAvoidsMouse) { | 628 TEST_F(StatusBubbleMacTest, BubbleAvoidsMouse) { |
632 NSWindow* window = test_window(); | 629 NSWindow* window = test_window(); |
633 | 630 |
634 // All coordinates here are relative to the window origin. | 631 // All coordinates here are relative to the window origin. |
635 | 632 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 backing:NSBackingStoreBuffered | 673 backing:NSBackingStoreBuffered |
677 defer:NO]); | 674 defer:NO]); |
678 | 675 |
679 // Switch parents with the bubble hidden. | 676 // Switch parents with the bubble hidden. |
680 bubble_->SwitchParentWindow(fullscreenParent); | 677 bubble_->SwitchParentWindow(fullscreenParent); |
681 | 678 |
682 // Switch back to the original parent with the bubble showing. | 679 // Switch back to the original parent with the bubble showing. |
683 bubble_->SetStatus(UTF8ToUTF16("Showing")); | 680 bubble_->SetStatus(UTF8ToUTF16("Showing")); |
684 bubble_->SwitchParentWindow(test_window()); | 681 bubble_->SwitchParentWindow(test_window()); |
685 } | 682 } |
OLD | NEW |