diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/cookie_details.h | 146 | ||||
-rw-r--r-- | chrome/browser/cocoa/cookie_details.mm | 221 | ||||
-rw-r--r-- | chrome/browser/cocoa/cookie_details_unittest.mm | 140 | ||||
-rw-r--r-- | chrome/browser/cocoa/cookie_prompt_window_controller.mm | 223 | ||||
-rw-r--r-- | chrome/browser/cocoa/cookie_tree_node.h | 72 | ||||
-rw-r--r-- | chrome/browser/cocoa/cookie_tree_node.mm | 156 | ||||
-rw-r--r-- | chrome/browser/cocoa/cookies_window_controller_unittest.mm | 92 |
7 files changed, 591 insertions, 459 deletions
diff --git a/chrome/browser/cocoa/cookie_details.h b/chrome/browser/cocoa/cookie_details.h new file mode 100644 index 0000000..2ce6dfa --- /dev/null +++ b/chrome/browser/cocoa/cookie_details.h @@ -0,0 +1,146 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +#include "chrome/browser/browsing_data_database_helper.h" +#include "chrome/browser/browsing_data_local_storage_helper.h" +#include "base/scoped_nsobject.h" +#include "net/base/cookie_monster.h" + +class CookieTreeNode; +class CookiePromptModalDialog; + +// This enum specifies the type of information contained in the +// cookie details. +enum CocoaCookieDetailsType { + // Represents grouping of cookie data, used in the cookie tree. + kCocoaCookieDetailsTypeFolder = 0, + + // Detailed information about a cookie, used both in the cookie + // tree and the cookie prompt. + kCocoaCookieDetailsTypeCookie = 1, + + // Detailed information about a web database used for + // display in the cookie tree. + kCocoaCookieDetailsTypeTreeDatabase = 2, + + // Detailed information about local storage used for + // display in the cookie tree. + kCocoaCookieDetailsTypeTreeLocalStorage = 3, + + // Detailed information about a web database used for display + // in the cookie prompt dialog. + kCocoaCookieDetailsTypePromptDatabase = 4, + + // Detailed information about local storage used for display + // in the cookie prompt dialog. + kCocoaCookieDetailsTypePromptLocalStorage = 5 +}; + +// This class contains all of the information that can be displayed in +// a cookie details view. Because the view uses bindings to display +// the cookie information, the methods that provide that information +// for display must be implemented directly on this class and not on any +// of its subclasses. +// If this system is rewritten to not use bindings, this class should be +// subclassed and specialized, rather than using an enum to determine type. +@interface CocoaCookieDetails : NSObject { + @private + CocoaCookieDetailsType type_; + + // These members are only set for type kCocoaCookieDetailsTypeCookie. + scoped_nsobject<NSString> content_; + scoped_nsobject<NSString> path_; + scoped_nsobject<NSString> sendFor_; + // Stringifed dates. + scoped_nsobject<NSString> created_; + scoped_nsobject<NSString> expires_; + + // These members are only set for types kCocoaCookieDetailsTypeCookie, + // kCocoaCookieDetailsTypePromptDatabase. + scoped_nsobject<NSString> name_; + + // Only set for types kCocoaCookieDetailsTypeTreeLocalStorage and + // kCocoaCookieDetailsTypeTreeDatabase nodes. + scoped_nsobject<NSString> fileSize_; + scoped_nsobject<NSString> lastModified_; + + // These members are only set for types kCocoaCookieDetailsTypeCookie, + // kCocoaCookieDetailsTypePromptDatabase and + // kCocoaCookieDetailsTypePromptLocalStorage nodes. + scoped_nsobject<NSString> domain_; + + // Used only for type kCocoaCookieTreeNodeTypeDatabaseStorage. + scoped_nsobject<NSString> databaseDescription_; + + // Used only for type kCocoaCookieDetailsTypePromptLocalStorage + scoped_nsobject<NSString> localStorageKey_; + scoped_nsobject<NSString> localStorageValue_; +} + +@property (readonly) CocoaCookieDetailsType type; + +// The following methods are used in the bindings of subviews inside +// the cookie detail view. Note that the method that tests the +// visibility of the subview for cookie-specific information has a different +// polarity than the other visibility testing methods. This ensures that +// this subview is shown when there is no selection in the cookie tree, +// because a hidden value of |false| is generated when the key value binding +// is evaluated through a nil object. The other methods are bound using a +// |NSNegateBoolean| transformer, so that when there is a empty selection the +// hidden value is |true|. +- (BOOL)shouldHideCookieDetailsView; +- (BOOL)shouldShowLocalStorageTreeDetailsView; +- (BOOL)shouldShowDatabaseTreeDetailsView; +- (BOOL)shouldShowDatabasePromptDetailsView; +- (BOOL)shouldShowLocalStoragePromptDetailsView; + +- (NSString*)name; +- (NSString*)content; +- (NSString*)domain; +- (NSString*)path; +- (NSString*)sendFor; +- (NSString*)created; +- (NSString*)expires; +- (NSString*)fileSize; +- (NSString*)lastModified; +- (NSString*)databaseDescription; +- (NSString*)localStorageKey; +- (NSString*)localStorageValue; + +// Used for folders in the cookie tree. +- (id)initAsFolder; + +// Used for cookie details in both the cookie tree and the cookie prompt dialog. +- (id)initWithCookie:(const net::CookieMonster::CanonicalCookie*)treeNode + origin:(NSString*)origin; + +// Used for database details in the cookie tree. +- (id)initWithDatabase: + (const BrowsingDataDatabaseHelper::DatabaseInfo*)databaseInfo; + +// Used for local storage details in the cookie tree. +- (id)initWithLocalStorage: + (const BrowsingDataLocalStorageHelper::LocalStorageInfo*)localStorageInfo; + +// Used for database details in the cookie prompt dialog. +- (id)initWithDatabase:(const std::string&)domain + name:(const string16&)name; + +// Used for local storage details in the cookie prompt dialog. +- (id)initWithLocalStorage:(const std::string&)domain + key:(const string16&)key + value:(const string16&)value; + +// A factory method to create a configured instance given a node from +// the cookie tree in |treeNode|. ++ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode; + +// A factory method to create a configured instance given a cookie prompt +// modal dialog in |dialog|. ++ (CocoaCookieDetails*)createFromPromptModalDialog: + (CookiePromptModalDialog*)dialog; + +@end diff --git a/chrome/browser/cocoa/cookie_details.mm b/chrome/browser/cocoa/cookie_details.mm new file mode 100644 index 0000000..7552c7f --- /dev/null +++ b/chrome/browser/cocoa/cookie_details.mm @@ -0,0 +1,221 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/cookie_details.h" + +#include "app/l10n_util_mac.h" +#import "base/i18n/time_formatting.h" +#include "base/sys_string_conversions.h" +#include "grit/generated_resources.h" +#include "chrome/browser/cookie_modal_dialog.h" +#include "chrome/browser/cookies_tree_model.h" + +@implementation CocoaCookieDetails + +@synthesize type = type_; + +- (BOOL)shouldHideCookieDetailsView { + return type_ != kCocoaCookieDetailsTypeFolder && + type_ != kCocoaCookieDetailsTypeCookie; +} + +- (BOOL)shouldShowLocalStorageTreeDetailsView { + return type_ == kCocoaCookieDetailsTypeTreeLocalStorage; +} + +- (BOOL)shouldShowDatabaseTreeDetailsView { + return type_ == kCocoaCookieDetailsTypeTreeDatabase; +} + +- (BOOL)shouldShowDatabasePromptDetailsView { + return type_ == kCocoaCookieDetailsTypePromptDatabase; +} + +- (BOOL)shouldShowLocalStoragePromptDetailsView { + return type_ == kCocoaCookieDetailsTypePromptLocalStorage; +} + +- (NSString*)name { + return name_.get(); +} + +- (NSString*)content { + return content_.get(); +} + +- (NSString*)domain { + return domain_.get(); +} + +- (NSString*)path { + return path_.get(); +} + +- (NSString*)sendFor { + return sendFor_.get(); +} + +- (NSString*)created { + return created_.get(); +} + +- (NSString*)expires { + return expires_.get(); +} + +- (NSString*)fileSize { + return fileSize_.get(); +} + +- (NSString*)lastModified { + return lastModified_.get(); +} + +- (NSString*)databaseDescription { + return databaseDescription_.get(); +} + +- (NSString*)localStorageKey { + return localStorageKey_.get(); +} + +- (NSString*)localStorageValue { + return localStorageValue_.get(); +} + +- (id)initAsFolder { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeFolder; + } + return self; +} + +- (id)initWithCookie:(const net::CookieMonster::CanonicalCookie*)cookie + origin:(NSString*)origin { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeCookie; + name_.reset([base::SysUTF8ToNSString(cookie->Name()) retain]); + content_.reset([base::SysUTF8ToNSString(cookie->Value()) retain]); + path_.reset([base::SysUTF8ToNSString(cookie->Path()) retain]); + domain_.reset([origin retain]); + + if (cookie->DoesExpire()) { + expires_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime(cookie->ExpiryDate())) retain]); + } else { + expires_.reset([l10n_util::GetNSStringWithFixup( + IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); + } + + created_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime(cookie->CreationDate())) retain]); + + if (cookie->IsSecure()) { + sendFor_.reset([l10n_util::GetNSStringWithFixup( + IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); + } else { + sendFor_.reset([l10n_util::GetNSStringWithFixup( + IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); + } + } + return self; +} + +- (id)initWithDatabase:(const BrowsingDataDatabaseHelper::DatabaseInfo*) + databaseInfo { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeTreeDatabase; + databaseDescription_.reset([base::SysUTF8ToNSString( + databaseInfo->description) retain]); + fileSize_.reset([base::SysWideToNSString(FormatBytes(databaseInfo->size, + GetByteDisplayUnits(databaseInfo->size), true)) retain]); + lastModified_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime( + databaseInfo->last_modified)) retain]); + } + return self; +} + +- (id)initWithLocalStorage:( + const BrowsingDataLocalStorageHelper::LocalStorageInfo*)storageInfo { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeTreeLocalStorage; + domain_.reset([base::SysUTF8ToNSString(storageInfo->origin) retain]); + fileSize_.reset([base::SysWideToNSString(FormatBytes(storageInfo->size, + GetByteDisplayUnits(storageInfo->size), true)) retain]); + lastModified_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime( + storageInfo->last_modified)) retain]); + } + return self; +} + +- (id)initWithDatabase:(const std::string&)domain + name:(const string16&)name { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypePromptDatabase; + name_.reset([base::SysUTF16ToNSString(name) retain]); + domain_.reset([base::SysUTF8ToNSString(domain) retain]); + } + return self; +} + +- (id)initWithLocalStorage:(const std::string&)domain + key:(const string16&)key + value:(const string16&)value { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypePromptLocalStorage; + domain_.reset([base::SysUTF8ToNSString(domain) retain]); + localStorageKey_.reset([base::SysUTF16ToNSString(key) retain]); + localStorageValue_.reset([base::SysUTF16ToNSString(value) retain]); + } + return self; +} + ++ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode { + CookieTreeNode::DetailedInfo info = treeNode->GetDetailedInfo(); + CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type; + if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { + NSString* origin = base::SysWideToNSString(info.origin.c_str()); + return [[[CocoaCookieDetails alloc] initWithCookie:&(info.cookie->second) + origin:origin] autorelease]; + } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { + return [[[CocoaCookieDetails alloc] + initWithDatabase:info.database_info] autorelease]; + } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { + return [[[CocoaCookieDetails alloc] + initWithLocalStorage:info.local_storage_info] autorelease]; + } else { + return [[[CocoaCookieDetails alloc] initAsFolder] autorelease]; + } +} + ++ (CocoaCookieDetails*)createFromPromptModalDialog:(CookiePromptModalDialog*) + dialog { + CookiePromptModalDialog::DialogType type(dialog->dialog_type()); + CocoaCookieDetails* details = nil; + if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { + net::CookieMonster::ParsedCookie pc(dialog->cookie_line()); + net::CookieMonster::CanonicalCookie cookie(dialog->origin(), pc); + const std::string& domain(pc.HasDomain() ? pc.Domain() : + dialog->origin().host()); + NSString* domainString = base::SysUTF8ToNSString(domain); + details = [[CocoaCookieDetails alloc] initWithCookie:&cookie + origin:domainString]; + } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { + details = [[CocoaCookieDetails alloc] + initWithLocalStorage:dialog->origin().host() + key:dialog->local_storage_key() + value:dialog->local_storage_value()]; + } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { + details = [[CocoaCookieDetails alloc] + initWithDatabase:dialog->origin().host() + name:dialog->database_name()]; + } else { + NOTIMPLEMENTED(); + } + return [details autorelease]; +} + +@end diff --git a/chrome/browser/cocoa/cookie_details_unittest.mm b/chrome/browser/cocoa/cookie_details_unittest.mm new file mode 100644 index 0000000..a600a8d --- /dev/null +++ b/chrome/browser/cocoa/cookie_details_unittest.mm @@ -0,0 +1,140 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/sys_string_conversions.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "chrome/browser/cocoa/cookie_details.h" +#include "googleurl/src/gurl.h" + +namespace { + +class CookiesDetailsTest : public CocoaTest { +}; + +TEST_F(CookiesDetailsTest, CreateForFolder) { + scoped_nsobject<CocoaCookieDetails> details; + details.reset([[CocoaCookieDetails alloc] initAsFolder]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeFolder); +} + +TEST_F(CookiesDetailsTest, CreateForCookie) { + scoped_nsobject<CocoaCookieDetails> details; + GURL url("http://chromium.org"); + std::string cookieLine( + "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); + net::CookieMonster::ParsedCookie pc(cookieLine); + net::CookieMonster::CanonicalCookie cookie(url, pc); + NSString* origin = base::SysUTF8ToNSString("http://chromium.org"); + details.reset([[CocoaCookieDetails alloc] initWithCookie:&cookie + origin:origin]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeCookie); + EXPECT_TRUE([@"PHPSESSID" isEqualToString:[details.get() name]]); + EXPECT_TRUE([@"0123456789abcdef0123456789abcdef" + isEqualToString:[details.get() content]]); + EXPECT_TRUE([@"http://chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"/" isEqualToString:[details.get() path]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() lastModified]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() created]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() sendFor]]); + + EXPECT_FALSE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForTreeDatabase) { + scoped_nsobject<CocoaCookieDetails> details; + std::string host("http://chromium.org"); + std::string database_name("sassolungo"); + std::string origin_identifier("dolomites"); + std::string description("a great place to climb"); + int64 size = 1234; + base::Time last_modified = base::Time::Now(); + BrowsingDataDatabaseHelper::DatabaseInfo info(host, database_name, + origin_identifier, description, size, last_modified); + details.reset([[CocoaCookieDetails alloc] initWithDatabase:&info]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeDatabase); + EXPECT_TRUE([@"a great place to climb" isEqualToString:[details.get() + databaseDescription]]); + EXPECT_TRUE([@"1234 B" isEqualToString:[details.get() fileSize]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() lastModified]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_TRUE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForTreeLocalStorage) { + scoped_nsobject<CocoaCookieDetails> details; + std::string protocol("http"); + std::string host("chromium.org"); + unsigned short port = 80; + std::string database_identifier("id"); + std::string origin("chromium.org"); + FilePath file_path(FilePath::FromWStringHack(std::wstring(L"/"))); + int64 size = 1234; + base::Time last_modified = base::Time::Now(); + BrowsingDataLocalStorageHelper::LocalStorageInfo info(protocol, host, port, + database_identifier, origin, file_path, size, last_modified); + details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:&info]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeLocalStorage); + EXPECT_TRUE([@"chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"1234 B" isEqualToString:[details.get() fileSize]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() lastModified]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_TRUE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForPromptDatabase) { + scoped_nsobject<CocoaCookieDetails> details; + std::string domain("chromium.org"); + string16 name(base::SysNSStringToUTF16(@"wicked_name")); + details.reset([[CocoaCookieDetails alloc] initWithDatabase:domain + name:name]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptDatabase); + EXPECT_TRUE([@"chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"wicked_name" isEqualToString:[details.get() name]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_TRUE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForPromptLocalStorage) { + scoped_nsobject<CocoaCookieDetails> details; + std::string domain("chromium.org"); + string16 key(base::SysNSStringToUTF16(@"testKey")); + string16 value(base::SysNSStringToUTF16(@"testValue")); + details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:domain + key:key + value:value]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptLocalStorage); + EXPECT_TRUE([@"chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"testKey" isEqualToString:[details.get() localStorageKey]]); + EXPECT_TRUE([@"testValue" isEqualToString:[details.get() localStorageValue]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_TRUE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +} diff --git a/chrome/browser/cocoa/cookie_prompt_window_controller.mm b/chrome/browser/cocoa/cookie_prompt_window_controller.mm index 5b85397..833423b 100644 --- a/chrome/browser/cocoa/cookie_prompt_window_controller.mm +++ b/chrome/browser/cocoa/cookie_prompt_window_controller.mm @@ -19,206 +19,42 @@ #include "grit/generated_resources.h" #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" -#pragma mark Window Controller - -// This class is an apapter allows the cookie details view to be shared -// by the cookie prompt window and the cookie tree in the cookies and -// other site data window. As instance of the class is set as the -// content object of the object controller for the details view and -// implements the methods expected by bindings inside that view. +#pragma mark Selection Adapter + +// The subpanes of the cookie details view expect to be able to bind to methods +// through a key path in the form |content.details.xxxx|. This class serves as +// an adapter that simply wraps a |CocoaCookieDetails| object. An instance of +// this class is set as the content object for cookie details view's object +// controller so that key paths are properly resolved through to the +// |CocoaCookieDetails| object for the cookie prompt. @interface CookiePromptSelectionAdapter : NSObject { @private - // The type of the cookie prompt being displayed, used to - // determine which subview of the details view is visible - CookiePromptModalDialog::DialogType promptType_; - - // The following members are used to hold information used in the - // cookie prompt detailed information for cookies and web databases. - scoped_nsobject<NSString> name_; - scoped_nsobject<NSString> domain_; - scoped_nsobject<NSString> content_; - - // The following members are used to hold information used in the - // cookie prompt detailed information for cookies only. - scoped_nsobject<NSString> path_; - scoped_nsobject<NSString> sendFor_; - scoped_nsobject<NSString> created_; - scoped_nsobject<NSString> expires_; - - // The following members are used to hold information used in the - // cookie prompt detailed information for local storage only. - scoped_nsobject<NSString> localStorageKey_; - scoped_nsobject<NSString> localStorageValue_; + scoped_nsobject<CocoaCookieDetails> details_; } -// Creates and returns an instance approriate for displaying information -// about a cookie. -- (id)initWithCookie:(const std::string&)cookie_line - url:(const GURL&)url; - -// Creates and returns an instance approriate for displaying information -// about a local storage. -- (id)initWithLocalStorage:(const std::string&)domain - key:(const string16&)key - value:(const string16&)value; - -// Creates and returns an instance approriate for displaying information -// about a web database. -- (id)initWithDatabase:(const std::string&)domain - name:(const string16&)name; - -// The following methods are all used in the bindings inside the cookie -// detail view. -@property (readonly) BOOL isFolderOrCookieTreeDetails; -@property (readonly) BOOL isLocalStorageTreeDetails; -@property (readonly) BOOL isDatabaseTreeDetails; -@property (readonly) BOOL isDatabasePromptDetails; -@property (readonly) BOOL isLocalStoragePromptDetails; -@property (readonly) NSString* name; -@property (readonly) NSString* content; -@property (readonly) NSString* domain; -@property (readonly) NSString* path; -@property (readonly) NSString* sendFor; -@property (readonly) NSString* created; -@property (readonly) NSString* expires; -@property (readonly) NSString* fileSize; -@property (readonly) NSString* lastModified; -@property (readonly) NSString* databaseDescription; -@property (readonly) NSString* localStorageKey; -@property (readonly) NSString* localStorageValue; - +- (CocoaCookieDetails*)details; +- (id)initWithDetails:(CocoaCookieDetails*)details; @end @implementation CookiePromptSelectionAdapter -- (id)initWithCookie:(const std::string&)cookie_line - url:(const GURL&)url { - if ((self = [super init])) { - promptType_ = CookiePromptModalDialog::DIALOG_TYPE_COOKIE; - net::CookieMonster::ParsedCookie pc(cookie_line); - net::CookieMonster::CanonicalCookie cookie(url, pc); - const std::string& domain(pc.HasDomain() ? pc.Domain() : url.host()); - domain_.reset([base::SysUTF8ToNSString(domain) retain]); - name_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); - content_.reset([base::SysUTF8ToNSString(cookie.Value()) retain]); - path_.reset([base::SysUTF8ToNSString(cookie.Path()) retain]); - - if (cookie.DoesExpire()) { - expires_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) - retain]); - } else { - expires_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); - } - - created_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())) - retain]); - - if (cookie.IsSecure()) { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); - } else { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); - } - } - return self; -} - -- (id)initWithLocalStorage:(const std::string&)domain - key:(const string16&)key - value:(const string16&)value { - if ((self = [super init])) { - promptType_ = CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE; - domain_.reset([base::SysUTF8ToNSString(domain) retain]); - localStorageKey_.reset([base::SysUTF16ToNSString(key) retain]); - localStorageValue_.reset([base::SysUTF16ToNSString(value) retain]); - } - return self; -} - -- (id)initWithDatabase:(const std::string&)domain - name:(const string16&)name { +// The adapter assumes ownership of the details object +// in its initializer. +- (id)initWithDetails:(CocoaCookieDetails*)details { if ((self = [super init])) { - promptType_ = CookiePromptModalDialog::DIALOG_TYPE_DATABASE; - name_.reset([base::SysUTF16ToNSString(name) retain]); - domain_.reset([base::SysUTF8ToNSString(domain) retain]); + details_.reset([details retain]); } return self; } -- (BOOL)isFolderOrCookieTreeDetails { - return promptType_ == CookiePromptModalDialog::DIALOG_TYPE_COOKIE; -} - -- (BOOL)isLocalStorageTreeDetails { - return false; -} - -- (BOOL)isDatabaseTreeDetails { - return false; -} - -- (BOOL) isDatabasePromptDetails { - return promptType_ == CookiePromptModalDialog::DIALOG_TYPE_DATABASE; -} - -- (BOOL) isLocalStoragePromptDetails { - return promptType_ == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE; -} - -- (NSString*)name { - return name_; -} - -- (NSString*)content { - return content_; -} - -- (NSString*)domain { - return domain_; -} - -- (NSString*)path { - return path_; -} - -- (NSString*)sendFor { - return sendFor_; -} - -- (NSString*)created { - return created_; -} - -- (NSString*)expires { - return expires_; -} - -- (NSString*)fileSize { - return nil; -} - -- (NSString*)lastModified { - return nil; -} - -- (NSString*)databaseDescription { - return nil; -} - -- (NSString*)localStorageKey { - return localStorageKey_; -} - -- (NSString*)localStorageValue { - return localStorageValue_; +- (CocoaCookieDetails*)details { + return details_.get(); } @end +#pragma mark Window Controller + @implementation CookiePromptWindowController - (id)initWithDialog:(CookiePromptModalDialog*)dialog { @@ -227,23 +63,10 @@ ofType:@"nib"]; if ((self = [super initWithWindowNibPath:nibpath owner:self])) { dialog_ = dialog; - CookiePromptModalDialog::DialogType type(dialog_->dialog_type()); - if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { - selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] - initWithCookie:dialog_->cookie_line() - url:dialog_->origin()]); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { - selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] - initWithLocalStorage:dialog_->origin().host() - key:dialog_->local_storage_key() - value:dialog_->local_storage_value()]); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { - selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] - initWithDatabase:dialog_->origin().host() - name:dialog_->database_name()]); - } else { - NOTIMPLEMENTED(); - } + CocoaCookieDetails* details = [CocoaCookieDetails + createFromPromptModalDialog:dialog]; + selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] + initWithDetails:details]); } return self; } diff --git a/chrome/browser/cocoa/cookie_tree_node.h b/chrome/browser/cocoa/cookie_tree_node.h index 66f5851..827c784 100644 --- a/chrome/browser/cocoa/cookie_tree_node.h +++ b/chrome/browser/cocoa/cookie_tree_node.h @@ -6,56 +6,13 @@ #include "base/scoped_nsobject.h" #include "chrome/browser/cookies_tree_model.h" +#include "chrome/browser/cocoa/cookie_details.h" -// This enum specifies the type of display node a CocoaCookieTreeNode is. If -// this system is rewritten to not use bindings, this class should be -// subclassed and specialized, rather than using an enum to determine type. -enum CocoaCookieTreeNodeType { - // Represents grouping data for the actual data. - kCocoaCookieTreeNodeTypeFolder = 0, - - // A cookie node. - kCocoaCookieTreeNodeTypeCookie = 1, - - // A HTML5 database storage node. - kCocoaCookieTreeNodeTypeDatabaseStorage = 2, - - // A local storage node. - kCocoaCookieTreeNodeTypeLocalStorage = 3 -}; - -// This class is used by CookiesWindowController and represents a node in the -// cookie tree view. @interface CocoaCookieTreeNode : NSObject { scoped_nsobject<NSString> title_; scoped_nsobject<NSMutableArray> children_; - - CocoaCookieTreeNodeType nodeType_; - - // The platform-independent model node. + scoped_nsobject<CocoaCookieDetails> details_; CookieTreeNode* treeNode_; // weak - - // These members are only set for kCocoaCookieTreeNodeTypeCookie nodes. - scoped_nsobject<NSString> name_; - scoped_nsobject<NSString> content_; - scoped_nsobject<NSString> path_; - scoped_nsobject<NSString> sendFor_; - // Stringifed dates. - scoped_nsobject<NSString> created_; - scoped_nsobject<NSString> expires_; - - // These members are only set for kCocoaCookieTreeNodeTypeLocalStorage - // and kCocoaCookieTreeNodeTypeDatabaseStorage nodes. - scoped_nsobject<NSString> fileSize_; - scoped_nsobject<NSString> lastModified_; - - // These members are only set for kCocoaCookieTreeNodeTypeCookie and - // kCocoaCookieTreeNodeTypeLocalStorage nodes. - scoped_nsobject<NSString> domain_; - - // These members are used only for nodes of type - // kCocoaCookieTreeNodeTypeDatabaseStorage. - scoped_nsobject<NSString> databaseDescription_; } // Designated initializer. @@ -66,7 +23,7 @@ enum CocoaCookieTreeNodeType { // Common getters.. - (NSString*)title; -- (CocoaCookieTreeNodeType)nodeType; +- (CocoaCookieDetailsType)nodeType; - (TreeModelNode*)treeNode; // |-mutableChildren| exists so that the CookiesTreeModelObserverBridge can @@ -75,27 +32,6 @@ enum CocoaCookieTreeNodeType { - (NSArray*)children; - (BOOL)isLeaf; -- (BOOL)isFolderOrCookieTreeDetails; -- (BOOL)isLocalStorageTreeDetails; -- (BOOL)isDatabaseTreeDetails; -- (BOOL)isLocalStoragePromptDetails; -- (BOOL)isDatabasePromptDetails; - -// Used only by kCocoaCookieTreeNodeTypeCookie. Nil for other types. -- (NSString*)name; -- (NSString*)content; -- (NSString*)domain; -- (NSString*)path; -- (NSString*)sendFor; -- (NSString*)created; -- (NSString*)expires; - -// Used by kCocoaCookieTreeNodeTypeLocalStorage and -// kCocoaCookieTreeNodeTypeDatabaseStorage nodes. Nil for other types. -- (NSString*)fileSize; -- (NSString*)lastModified; - -// Used by kCocoaCookieTreeNodeTypeDatabaseStorage nodes. Nil for other types. -- (NSString*)databaseDescription; +- (CocoaCookieDetails*)details; @end diff --git a/chrome/browser/cocoa/cookie_tree_node.mm b/chrome/browser/cocoa/cookie_tree_node.mm index 376df82..553a7bb 100644 --- a/chrome/browser/cocoa/cookie_tree_node.mm +++ b/chrome/browser/cocoa/cookie_tree_node.mm @@ -4,11 +4,7 @@ #import "chrome/browser/cocoa/cookie_tree_node.h" -#include "app/l10n_util_mac.h" -#import "base/i18n/time_formatting.h" #include "base/sys_string_conversions.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "grit/generated_resources.h" @implementation CocoaCookieTreeNode @@ -24,68 +20,17 @@ - (void)rebuild { title_.reset([base::SysWideToNSString(treeNode_->GetTitle()) retain]); children_.reset(); - nodeType_ = kCocoaCookieTreeNodeTypeFolder; - - CookieTreeNode::DetailedInfo info = treeNode_->GetDetailedInfo(); - CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type; - if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { - nodeType_ = kCocoaCookieTreeNodeTypeCookie; - net::CookieMonster::CanonicalCookie cookie = info.cookie->second; - - name_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); - title_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); - content_.reset([base::SysUTF8ToNSString(cookie.Value()) retain]); - path_.reset([base::SysUTF8ToNSString(cookie.Path()) retain]); - domain_.reset([base::SysWideToNSString(info.origin) retain]); - - if (cookie.DoesExpire()) { - expires_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) retain]); - } else { - expires_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); - } - - created_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())) retain]); - - if (cookie.IsSecure()) { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); - } else { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); - } - } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { - const BrowsingDataDatabaseHelper::DatabaseInfo* databaseInfo = - info.database_info; - nodeType_ = kCocoaCookieTreeNodeTypeDatabaseStorage; - databaseDescription_.reset([base::SysUTF8ToNSString( - databaseInfo->description) retain]); - fileSize_.reset([base::SysWideToNSString(FormatBytes(databaseInfo->size, - GetByteDisplayUnits(databaseInfo->size), true)) retain]); - lastModified_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime( - databaseInfo->last_modified)) retain]); - } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { - const BrowsingDataLocalStorageHelper::LocalStorageInfo* storageInfo = - info.local_storage_info; - nodeType_ = kCocoaCookieTreeNodeTypeLocalStorage; - domain_.reset([base::SysUTF8ToNSString(storageInfo->origin) retain]); - fileSize_.reset([base::SysWideToNSString(FormatBytes(storageInfo->size, - GetByteDisplayUnits(storageInfo->size), true)) retain]); - lastModified_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime( - storageInfo->last_modified)) retain]); - } + // The tree node assumes ownership of the cookie details object + details_.reset([[CocoaCookieDetails createFromCookieTreeNode:(treeNode_)] + retain]); } - (NSString*)title { return title_.get(); } -- (CocoaCookieTreeNodeType)nodeType { - return nodeType_; +- (CocoaCookieDetailsType)nodeType { + return [details_.get() type]; } - (TreeModelNode*)treeNode { @@ -111,8 +56,8 @@ } - (BOOL)isLeaf { - return nodeType_ != kCocoaCookieTreeNodeTypeFolder; -} + return [self nodeType] != kCocoaCookieDetailsTypeFolder; +}; - (NSString*)description { NSString* format = @@ -121,91 +66,8 @@ [self nodeType], [[self children] count]]; } -- (BOOL)isFolderOrCookieTreeDetails { - return [self nodeType] == kCocoaCookieTreeNodeTypeFolder || - [self nodeType] == kCocoaCookieTreeNodeTypeCookie; -} - -- (BOOL)isDatabaseTreeDetails { - return [self nodeType] == kCocoaCookieTreeNodeTypeDatabaseStorage; -} - -- (BOOL)isLocalStorageTreeDetails { - return [self nodeType] == kCocoaCookieTreeNodeTypeLocalStorage; -} - -- (BOOL)isDatabasePromptDetails { - return false; -} - -- (BOOL)isLocalStoragePromptDetails { - return false; -} - -#pragma mark Cookie Accessors - -- (NSString*)name { - return name_.get(); -} - -- (NSString*)content { - return content_.get(); -} - -- (NSString*)domain { - return domain_.get(); -} - -- (NSString*)path { - return path_.get(); -} - -- (NSString*)sendFor { - return sendFor_.get(); -} - -- (NSString*)created { - return created_.get(); -} - -- (NSString*)expires { - return expires_.get(); -} - -#pragma mark Local Storage and Database Accessors - -- (NSString*)fileSize { - return fileSize_.get(); -} - -- (NSString*)lastModified { - return lastModified_.get(); -} - -#pragma mark Database Accessors - -- (NSString*)databaseDescription { - return databaseDescription_.get(); -} - -#pragma mark Unused Accessors - -// This method is never called for the cookie tree, it is only -// only included because the Cocoa bindings for the shared view -// used to display browser data details always expects the method -// even though it is only used in the cookie prompt window. -- (id)localStorageKey { - NOTIMPLEMENTED(); - return nil; -} - -// This method is never called for the cookie tree, it is only -// only included because the Cocoa bindings for the shared view -// used to display browser data details always expects the method -// even though it is only used in the cookie prompt window. -- (id)localStorageValue { - NOTIMPLEMENTED(); - return nil; +- (CocoaCookieDetails*)details { + return details_; } @end diff --git a/chrome/browser/cocoa/cookies_window_controller_unittest.mm b/chrome/browser/cocoa/cookies_window_controller_unittest.mm index fb19db3..898ed9e 100644 --- a/chrome/browser/cocoa/cookies_window_controller_unittest.mm +++ b/chrome/browser/cocoa/cookies_window_controller_unittest.mm @@ -141,14 +141,15 @@ TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeCookie) { TreeModelNode* node = model.GetRoot()->GetChild(0)->GetChild(0)->GetChild(0); CocoaCookieTreeNode* cookie = CocoaNodeFromTreeNode(node); - EXPECT_TRUE([@"B" isEqualToString:[cookie content]]); - EXPECT_TRUE([@"When I close my browser" isEqualToString:[cookie expires]]); - EXPECT_TRUE([@"Any kind of connection" isEqualToString:[cookie sendFor]]); + CocoaCookieDetails* details = [cookie details]; + EXPECT_TRUE([@"B" isEqualToString:[details content]]); + EXPECT_TRUE([@"When I close my browser" isEqualToString:[details expires]]); + EXPECT_TRUE([@"Any kind of connection" isEqualToString:[details sendFor]]); EXPECT_TRUE([@"A" isEqualToString:[cookie title]]); - EXPECT_TRUE([@"A" isEqualToString:[cookie name]]); - EXPECT_TRUE([@"/" isEqualToString:[cookie path]]); + EXPECT_TRUE([@"A" isEqualToString:[details name]]); + EXPECT_TRUE([@"/" isEqualToString:[details path]]); EXPECT_EQ(0U, [[cookie children] count]); - EXPECT_TRUE([cookie created]); + EXPECT_TRUE([details created]); EXPECT_TRUE([cookie isLeaf]); EXPECT_EQ(node, [cookie treeNode]); } @@ -179,15 +180,16 @@ TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeRecursive) { EXPECT_EQ(node->GetChild(0), [cookies treeNode]); // Test cookie node. This is the same as CocoaNodeFromTreeNodeCookie. - EXPECT_TRUE([@"B" isEqualToString:[cookie content]]); - EXPECT_TRUE([@"When I close my browser" isEqualToString:[cookie expires]]); - EXPECT_TRUE([@"Any kind of connection" isEqualToString:[cookie sendFor]]); + CocoaCookieDetails* details = [cookie details]; + EXPECT_TRUE([@"B" isEqualToString:[details content]]); + EXPECT_TRUE([@"When I close my browser" isEqualToString:[details expires]]); + EXPECT_TRUE([@"Any kind of connection" isEqualToString:[details sendFor]]); EXPECT_TRUE([@"A" isEqualToString:[cookie title]]); - EXPECT_TRUE([@"A" isEqualToString:[cookie name]]); - EXPECT_TRUE([@"/" isEqualToString:[cookie path]]); - EXPECT_TRUE([@"foo.com" isEqualToString:[cookie domain]]); + EXPECT_TRUE([@"A" isEqualToString:[details name]]); + EXPECT_TRUE([@"/" isEqualToString:[details path]]); + EXPECT_TRUE([@"foo.com" isEqualToString:[details domain]]); EXPECT_EQ(0U, [[cookie children] count]); - EXPECT_TRUE([cookie created]); + EXPECT_TRUE([details created]); EXPECT_TRUE([cookie isLeaf]); EXPECT_EQ(node->GetChild(0)->GetChild(0), [cookie treeNode]); } @@ -261,7 +263,7 @@ TEST_F(CookiesWindowControllerTest, TreeNodesRemoved) { EXPECT_EQ(1U, [cocoa_children count]); - NSString* title = [[cocoa_children objectAtIndex:0] name]; + NSString* title = [[[cocoa_children objectAtIndex:0] details] name]; EXPECT_TRUE([@"A" isEqualToString:title]); } @@ -286,11 +288,11 @@ TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) { // Check default ordering. CocoaCookieTreeNode* node = [cocoa_children objectAtIndex:0]; - EXPECT_TRUE([@"A" isEqualToString:[node name]]); + EXPECT_TRUE([@"A" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:1]; - EXPECT_TRUE([@"C" isEqualToString:[node name]]); + EXPECT_TRUE([@"C" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:2]; - EXPECT_TRUE([@"E" isEqualToString:[node name]]); + EXPECT_TRUE([@"E" isEqualToString:[[node details] name]]); CookiesTreeModel* model = [controller_ treeModel]; // Root --> foo.com --> Cookies. @@ -307,11 +309,11 @@ TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) { // Check the new order. node = [cocoa_children objectAtIndex:0]; - EXPECT_TRUE([@"E" isEqualToString:[node name]]); + EXPECT_TRUE([@"E" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:1]; - EXPECT_TRUE([@"A" isEqualToString:[node name]]); + EXPECT_TRUE([@"A" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:2]; - EXPECT_TRUE([@"C" isEqualToString:[node name]]); + EXPECT_TRUE([@"C" isEqualToString:[[node details] name]]); } TEST_F(CookiesWindowControllerTest, TreeNodeChanged) { @@ -590,43 +592,45 @@ TEST_F(CookiesWindowControllerTest, CreateDatabaseStorageNodes) { CocoaCookieTreeNode* node = [[[controller_ cocoaTreeModel] children] objectAtIndex:0]; EXPECT_TRUE([@"gdbhost1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host1 --> Web Databases. node = [[node children] lastObject]; EXPECT_TRUE([@"Web Databases" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Database Storage --> db1. node = [[node children] lastObject]; EXPECT_TRUE([@"db1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeDatabaseStorage, [node nodeType]); - EXPECT_TRUE([@"description 1" isEqualToString:[node databaseDescription]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); + CocoaCookieDetails* details = [node details]; + EXPECT_TRUE([@"description 1" isEqualToString:[details databaseDescription]]); + EXPECT_TRUE([details lastModified]); + EXPECT_TRUE([details fileSize]); // Root --> gdbhost2. node = [[[controller_ cocoaTreeModel] children] objectAtIndex:1]; EXPECT_TRUE([@"gdbhost2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host1 --> Web Databases. node = [[node children] lastObject]; EXPECT_TRUE([@"Web Databases" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Database Storage --> db2. node = [[node children] lastObject]; EXPECT_TRUE([@"db2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeDatabaseStorage, [node nodeType]); - EXPECT_TRUE([@"description 2" isEqualToString:[node databaseDescription]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); + details = [node details]; + EXPECT_TRUE([@"description 2" isEqualToString:[details databaseDescription]]); + EXPECT_TRUE([details lastModified]); + EXPECT_TRUE([details fileSize]); } TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { @@ -649,43 +653,43 @@ TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { CocoaCookieTreeNode* node = [[[controller_ cocoaTreeModel] children] objectAtIndex:2]; EXPECT_TRUE([@"host1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host1 --> Local Storage. node = [[node children] lastObject]; EXPECT_TRUE([@"Local Storage" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Local Storage --> origin1. node = [[node children] lastObject]; EXPECT_TRUE([@"origin1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeLocalStorage, [node nodeType]); - EXPECT_TRUE([@"origin1" isEqualToString:[node domain]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); + EXPECT_TRUE([@"origin1" isEqualToString:[[node details] domain]]); + EXPECT_TRUE([[node details] lastModified]); + EXPECT_TRUE([[node details] fileSize]); // Root --> host2. node = [[[controller_ cocoaTreeModel] children] objectAtIndex:3]; EXPECT_TRUE([@"host2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host2 --> Local Storage. node = [[node children] lastObject]; EXPECT_TRUE([@"Local Storage" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Local Storage --> origin2. node = [[node children] lastObject]; EXPECT_TRUE([@"origin2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeLocalStorage, [node nodeType]); - EXPECT_TRUE([@"origin2" isEqualToString:[node domain]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); + EXPECT_TRUE([@"origin2" isEqualToString:[[node details] domain]]); + EXPECT_TRUE([[node details] lastModified]); + EXPECT_TRUE([[node details] fileSize]); } } // namespace |