Chromium Code Reviews

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm

Issue 3083022: Rework gfx::Font by moving platform-specific code into inner classes.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
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 "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" 5 #import "chrome/browser/autocomplete/autocomplete_popup_view_mac.h"
6 6
7 #include "app/text_elider.h" 7 #include "app/text_elider.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete.h" 10 #include "chrome/browser/autocomplete/autocomplete.h"
11 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
12 12
13 namespace { 13 namespace {
14 14
15 const float kLargeWidth = 10000; 15 const float kLargeWidth = 10000;
16 16
17 class AutocompletePopupViewMacTest : public PlatformTest { 17 class AutocompletePopupViewMacTest : public PlatformTest {
18 public: 18 public:
19 AutocompletePopupViewMacTest() {} 19 AutocompletePopupViewMacTest() {}
20 20
21 virtual void SetUp() { 21 virtual void SetUp() {
22 PlatformTest::SetUp(); 22 PlatformTest::SetUp();
23 23
24 // These are here because there is no autorelease pool for the 24 // These are here because there is no autorelease pool for the
25 // constructor. 25 // constructor.
26 color_ = [NSColor blackColor]; 26 color_ = [NSColor blackColor];
27 font_ = gfx::Font::CreateFont( 27 font_ = gfx::Font(
28 base::SysNSStringToWide([[NSFont userFontOfSize:12] fontName]), 12); 28 base::SysNSStringToWide([[NSFont userFontOfSize:12] fontName]), 12);
29 } 29 }
30 30
31 // Returns the length of the run starting at |location| for which 31 // Returns the length of the run starting at |location| for which
32 // |attributeName| remains the same. 32 // |attributeName| remains the same.
33 static NSUInteger RunLengthForAttribute(NSAttributedString* string, 33 static NSUInteger RunLengthForAttribute(NSAttributedString* string,
34 NSUInteger location, 34 NSUInteger location,
35 NSString* attributeName) { 35 NSString* attributeName) {
36 const NSRange fullRange = NSMakeRange(0, [string length]); 36 const NSRange fullRange = NSMakeRange(0, [string length]);
37 NSRange range; 37 NSRange range;
(...skipping 382 matching lines...)
420 } 420 }
421 421
422 TEST_F(AutocompletePopupViewMacTest, ElideString) { 422 TEST_F(AutocompletePopupViewMacTest, ElideString) {
423 NSString* const contents = @"This is a test with long contents"; 423 NSString* const contents = @"This is a test with long contents";
424 const std::wstring wideContents(base::SysNSStringToWide(contents)); 424 const std::wstring wideContents(base::SysNSStringToWide(contents));
425 425
426 const float kWide = 1000.0; 426 const float kWide = 1000.0;
427 const float kNarrow = 20.0; 427 const float kNarrow = 20.0;
428 428
429 NSDictionary* attributes = 429 NSDictionary* attributes =
430 [NSDictionary dictionaryWithObject:font_.nativeFont() 430 [NSDictionary dictionaryWithObject:font_.GetNativeFont()
431 forKey:NSFontAttributeName]; 431 forKey:NSFontAttributeName];
432 scoped_nsobject<NSMutableAttributedString> as( 432 scoped_nsobject<NSMutableAttributedString> as(
433 [[NSMutableAttributedString alloc] initWithString:contents 433 [[NSMutableAttributedString alloc] initWithString:contents
434 attributes:attributes]); 434 attributes:attributes]);
435 435
436 // Nothing happens if the space is really wide. 436 // Nothing happens if the space is really wide.
437 NSMutableAttributedString* ret = 437 NSMutableAttributedString* ret =
438 AutocompletePopupViewMac::ElideString(as, wideContents, font_, kWide); 438 AutocompletePopupViewMac::ElideString(as, wideContents, font_, kWide);
439 EXPECT_TRUE(ret == as); 439 EXPECT_TRUE(ret == as);
440 EXPECT_TRUE([[as string] isEqualToString:contents]); 440 EXPECT_TRUE([[as string] isEqualToString:contents]);
(...skipping 28 matching lines...)
469 m.contents_class.push_back( 469 m.contents_class.push_back(
470 ACMatchClassification(0, ACMatchClassification::NONE)); 470 ACMatchClassification(0, ACMatchClassification::NONE));
471 m.contents_class.push_back( 471 m.contents_class.push_back(
472 ACMatchClassification(runLength1, ACMatchClassification::MATCH)); 472 ACMatchClassification(runLength1, ACMatchClassification::MATCH));
473 m.contents_class.push_back( 473 m.contents_class.push_back(
474 ACMatchClassification(runLength1 + runLength2, 474 ACMatchClassification(runLength1 + runLength2,
475 ACMatchClassification::URL)); 475 ACMatchClassification::URL));
476 476
477 // Figure out the width of the contents. 477 // Figure out the width of the contents.
478 NSDictionary* attributes = 478 NSDictionary* attributes =
479 [NSDictionary dictionaryWithObject:font_.nativeFont() 479 [NSDictionary dictionaryWithObject:font_.GetNativeFont()
480 forKey:NSFontAttributeName]; 480 forKey:NSFontAttributeName];
481 const float contentsWidth = [contents sizeWithAttributes:attributes].width; 481 const float contentsWidth = [contents sizeWithAttributes:attributes].width;
482 482
483 // After accounting for the width of the image, this will force us 483 // After accounting for the width of the image, this will force us
484 // to elide the contents. 484 // to elide the contents.
485 float cellWidth = ceil(contentsWidth / 0.7); 485 float cellWidth = ceil(contentsWidth / 0.7);
486 486
487 NSAttributedString* decorated = 487 NSAttributedString* decorated =
488 AutocompletePopupViewMac::MatchText(m, font_, cellWidth); 488 AutocompletePopupViewMac::MatchText(m, font_, cellWidth);
489 489
(...skipping 33 matching lines...)
523 // updates the model's selection from the matrix before returning. 523 // updates the model's selection from the matrix before returning.
524 // Could possibly test that via -select:. 524 // Could possibly test that via -select:.
525 525
526 // TODO(shess): Test that AutocompleteButtonCell returns the right 526 // TODO(shess): Test that AutocompleteButtonCell returns the right
527 // background colors for on, highlighted, and neither. 527 // background colors for on, highlighted, and neither.
528 528
529 // TODO(shess): Test that AutocompleteMatrixTarget can be initialized 529 // TODO(shess): Test that AutocompleteMatrixTarget can be initialized
530 // and then sends -select: to the view. 530 // and then sends -select: to the view.
531 531
532 } // namespace 532 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_popup_view_mac.mm ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine