OLD | NEW |
1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009-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 #include "app/tree_model.h" | 7 #include "app/tree_model.h" |
8 #import "base/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "chrome/browser/cocoa/browser_test_helper.h" | 10 #include "chrome/browser/cocoa/browser_test_helper.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 CocoaCookieTreeNode* FindCocoaNode(TreeModelNode* node, | 68 CocoaCookieTreeNode* FindCocoaNode(TreeModelNode* node, |
69 CocoaCookieTreeNode* start) { | 69 CocoaCookieTreeNode* start) { |
70 return [controller_ modelObserver]->FindCocoaNode(node, start); | 70 return [controller_ modelObserver]->FindCocoaNode(node, start); |
71 } | 71 } |
72 | 72 |
73 protected: | 73 protected: |
74 BrowserTestHelper browser_helper_; | 74 BrowserTestHelper browser_helper_; |
75 scoped_nsobject<CookiesWindowController> controller_; | 75 scoped_nsobject<CookiesWindowController> controller_; |
76 BrowsingDataLocalStorageHelper* local_storage_helper_; | 76 MockBrowsingDataLocalStorageHelper* local_storage_helper_; |
77 }; | 77 }; |
78 | 78 |
79 TEST_F(CookiesWindowControllerTest, Construction) { | 79 TEST_F(CookiesWindowControllerTest, Construction) { |
80 std::vector<SkBitmap> skia_icons; | 80 std::vector<SkBitmap> skia_icons; |
81 [controller_ treeModel]->GetIcons(&skia_icons); | 81 [controller_ treeModel]->GetIcons(&skia_icons); |
82 | 82 |
83 EXPECT_EQ([[controller_ icons] count], skia_icons.size() + 1U); | 83 EXPECT_EQ([[controller_ icons] count], skia_icons.size() + 1U); |
84 } | 84 } |
85 | 85 |
86 TEST_F(CookiesWindowControllerTest, FindCocoaNodeRoot) { | 86 TEST_F(CookiesWindowControllerTest, FindCocoaNodeRoot) { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 430 |
431 TEST_F(CookiesWindowControllerTest, RemoveButtonEnabled) { | 431 TEST_F(CookiesWindowControllerTest, RemoveButtonEnabled) { |
432 const GURL url = GURL("http://foo.com"); | 432 const GURL url = GURL("http://foo.com"); |
433 TestingProfile* profile = browser_helper_.profile(); | 433 TestingProfile* profile = browser_helper_.profile(); |
434 net::CookieMonster* cm = profile->GetCookieMonster(); | 434 net::CookieMonster* cm = profile->GetCookieMonster(); |
435 cm->SetCookie(url, "A=B"); | 435 cm->SetCookie(url, "A=B"); |
436 cm->SetCookie(url, "C=D"); | 436 cm->SetCookie(url, "C=D"); |
437 | 437 |
438 // This will clean itself up when we call |-closeSheet:|. If we reset the | 438 // This will clean itself up when we call |-closeSheet:|. If we reset the |
439 // scoper, we'd get a double-free. | 439 // scoper, we'd get a double-free. |
| 440 local_storage_helper_ = new MockBrowsingDataLocalStorageHelper(profile); |
| 441 local_storage_helper_->AddLocalStorageSamples(); |
440 CookiesWindowController* controller = | 442 CookiesWindowController* controller = |
441 [[CookiesWindowController alloc] initWithProfile:profile | 443 [[CookiesWindowController alloc] initWithProfile:profile |
442 storageHelper:local_storage_helper_]; | 444 storageHelper:local_storage_helper_]; |
| 445 local_storage_helper_->Notify(); |
443 [controller attachSheetTo:test_window()]; | 446 [controller attachSheetTo:test_window()]; |
444 | 447 |
445 // Nothing should be selected right now. | 448 // Nothing should be selected right now. |
446 EXPECT_FALSE([controller removeButtonEnabled]); | 449 EXPECT_FALSE([controller removeButtonEnabled]); |
447 | 450 |
448 { | 451 { |
449 // Pretend to select cookie A. | 452 // Pretend to select cookie A. |
450 NSUInteger path[3] = {0, 0, 0}; | 453 NSUInteger path[3] = {0, 0, 0}; |
451 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; | 454 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; |
452 [[controller treeController] setSelectionIndexPath:indexPath]; | 455 [[controller treeController] setSelectionIndexPath:indexPath]; |
453 [controller outlineViewSelectionDidChange:nil]; | 456 [controller outlineViewSelectionDidChange:nil]; |
454 EXPECT_TRUE([controller removeButtonEnabled]); | 457 EXPECT_TRUE([controller removeButtonEnabled]); |
| 458 EXPECT_FALSE([[controller cookieInfoView] isHidden]); |
| 459 EXPECT_TRUE([[controller localStorageInfoView] isHidden]); |
455 } | 460 } |
456 | 461 |
457 { | 462 { |
458 // Pretend to select cookie C. | 463 // Pretend to select cookie C. |
459 NSUInteger path[3] = {0, 0, 1}; | 464 NSUInteger path[3] = {0, 0, 1}; |
460 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; | 465 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; |
461 [[controller treeController] setSelectionIndexPath:indexPath]; | 466 [[controller treeController] setSelectionIndexPath:indexPath]; |
462 [controller outlineViewSelectionDidChange:nil]; | 467 [controller outlineViewSelectionDidChange:nil]; |
463 EXPECT_TRUE([controller removeButtonEnabled]); | 468 EXPECT_TRUE([controller removeButtonEnabled]); |
| 469 EXPECT_FALSE([[controller cookieInfoView] isHidden]); |
| 470 EXPECT_TRUE([[controller localStorageInfoView] isHidden]); |
464 } | 471 } |
465 | 472 |
466 { | 473 { |
| 474 // Select a local storage node. |
| 475 NSUInteger path[3] = {2, 0, 0}; |
| 476 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; |
| 477 [[controller treeController] setSelectionIndexPath:indexPath]; |
| 478 [controller outlineViewSelectionDidChange:nil]; |
| 479 EXPECT_TRUE([controller removeButtonEnabled]); |
| 480 EXPECT_TRUE([[controller cookieInfoView] isHidden]); |
| 481 EXPECT_FALSE([[controller localStorageInfoView] isHidden]); |
| 482 } |
| 483 |
| 484 { |
467 // Pretend to select something that isn't there! | 485 // Pretend to select something that isn't there! |
468 NSUInteger path[3] = {0, 0, 2}; | 486 NSUInteger path[3] = {0, 0, 2}; |
469 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; | 487 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; |
470 [[controller treeController] setSelectionIndexPath:indexPath]; | 488 [[controller treeController] setSelectionIndexPath:indexPath]; |
471 [controller outlineViewSelectionDidChange:nil]; | 489 [controller outlineViewSelectionDidChange:nil]; |
472 EXPECT_FALSE([controller removeButtonEnabled]); | 490 EXPECT_FALSE([controller removeButtonEnabled]); |
473 } | 491 } |
474 | 492 |
475 { | 493 { |
476 // Try selecting something that doesn't exist again. | 494 // Try selecting something that doesn't exist again. |
477 NSUInteger path[3] = {3, 1, 4}; | 495 NSUInteger path[3] = {7, 1, 4}; |
478 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; | 496 NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:path length:3]; |
479 [[controller treeController] setSelectionIndexPath:indexPath]; | 497 [[controller treeController] setSelectionIndexPath:indexPath]; |
480 [controller outlineViewSelectionDidChange:nil]; | 498 [controller outlineViewSelectionDidChange:nil]; |
481 EXPECT_FALSE([controller removeButtonEnabled]); | 499 EXPECT_FALSE([controller removeButtonEnabled]); |
482 } | 500 } |
483 | 501 |
484 [controller closeSheet:nil]; | 502 [controller closeSheet:nil]; |
485 } | 503 } |
486 | 504 |
487 TEST_F(CookiesWindowControllerTest, UpdateFilter) | 505 TEST_F(CookiesWindowControllerTest, UpdateFilter) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 [field setStringValue:@"e"]; | 547 [field setStringValue:@"e"]; |
530 [controller_ updateFilter:field]; | 548 [controller_ updateFilter:field]; |
531 EXPECT_EQ(0U, [[[controller_ cocoaTreeModel] children] count]); | 549 EXPECT_EQ(0U, [[[controller_ cocoaTreeModel] children] count]); |
532 | 550 |
533 // Search for "aa". | 551 // Search for "aa". |
534 [field setStringValue:@"aa"]; | 552 [field setStringValue:@"aa"]; |
535 [controller_ updateFilter:field]; | 553 [controller_ updateFilter:field]; |
536 EXPECT_EQ(1U, [[[controller_ cocoaTreeModel] children] count]); | 554 EXPECT_EQ(1U, [[[controller_ cocoaTreeModel] children] count]); |
537 } | 555 } |
538 | 556 |
| 557 TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { |
| 558 TestingProfile* profile = browser_helper_.profile(); |
| 559 net::CookieMonster* cm = profile->GetCookieMonster(); |
| 560 cm->SetCookie(GURL("http://google.com"), "A=B"); |
| 561 cm->SetCookie(GURL("http://dev.chromium.org"), "C=D"); |
| 562 local_storage_helper_ = new MockBrowsingDataLocalStorageHelper(profile); |
| 563 local_storage_helper_->AddLocalStorageSamples(); |
| 564 controller_.reset( |
| 565 [[CookiesWindowController alloc] initWithProfile:profile |
| 566 storageHelper:local_storage_helper_]); |
| 567 local_storage_helper_->Notify(); |
| 568 |
| 569 ASSERT_EQ(4U, [[[controller_ cocoaTreeModel] children] count]); |
| 570 |
| 571 // Root --> host1. |
| 572 CocoaCookieTreeNode* node = |
| 573 [[[controller_ cocoaTreeModel] children] objectAtIndex:2]; |
| 574 EXPECT_TRUE([@"host1" isEqualToString:[node title]]); |
| 575 EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); |
| 576 EXPECT_EQ(1U, [[node children] count]); |
| 577 |
| 578 // host1 --> Local Storage. |
| 579 node = [[node children] lastObject]; |
| 580 EXPECT_TRUE([@"Local Storage" isEqualToString:[node title]]); |
| 581 EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); |
| 582 EXPECT_EQ(1U, [[node children] count]); |
| 583 |
| 584 // Local Storage --> origin1. |
| 585 node = [[node children] lastObject]; |
| 586 EXPECT_TRUE([@"origin1" isEqualToString:[node title]]); |
| 587 EXPECT_EQ(kCocoaCookieTreeNodeTypeLocalStorage, [node nodeType]); |
| 588 EXPECT_TRUE([@"origin1" isEqualToString:[node domain]]); |
| 589 EXPECT_TRUE([node lastModified]); |
| 590 EXPECT_TRUE([node fileSize]); |
| 591 |
| 592 // Root --> host2. |
| 593 node = |
| 594 [[[controller_ cocoaTreeModel] children] objectAtIndex:3]; |
| 595 EXPECT_TRUE([@"host2" isEqualToString:[node title]]); |
| 596 EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); |
| 597 EXPECT_EQ(1U, [[node children] count]); |
| 598 |
| 599 // host2 --> Local Storage. |
| 600 node = [[node children] lastObject]; |
| 601 EXPECT_TRUE([@"Local Storage" isEqualToString:[node title]]); |
| 602 EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); |
| 603 EXPECT_EQ(1U, [[node children] count]); |
| 604 |
| 605 // Local Storage --> origin2. |
| 606 node = [[node children] lastObject]; |
| 607 EXPECT_TRUE([@"origin2" isEqualToString:[node title]]); |
| 608 EXPECT_EQ(kCocoaCookieTreeNodeTypeLocalStorage, [node nodeType]); |
| 609 EXPECT_TRUE([@"origin2" isEqualToString:[node domain]]); |
| 610 EXPECT_TRUE([node lastModified]); |
| 611 EXPECT_TRUE([node fileSize]); |
| 612 } |
| 613 |
539 } // namespace | 614 } // namespace |
OLD | NEW |