Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / content_settings / cookie_details_view_controller_unittest.mm
blob789e64f3b1a74256953997962394493c74ba1d86
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/sys_string_conversions.h"
6 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
7 #include "chrome/browser/ui/cocoa/content_settings/cookie_details.h"
8 #include "chrome/browser/ui/cocoa/content_settings/cookie_details_view_controller.h"
9 #include "net/cookies/canonical_cookie.h"
10 #include "net/cookies/parsed_cookie.h"
12 namespace {
14 class CookieDetailsViewControllerTest : public CocoaTest {
17 static CocoaCookieDetails* CreateTestCookieDetails(BOOL canEditExpiration) {
18   GURL url("http://chromium.org");
19   std::string cookieLine(
20       "PHPSESSID=0123456789abcdef0123456789abcdef; path=/");
21   net::ParsedCookie pc(cookieLine);
22   net::CanonicalCookie cookie(url, pc);
23   CocoaCookieDetails* details = [CocoaCookieDetails alloc];
24   [details initWithCookie:&cookie
25         canEditExpiration:canEditExpiration];
26   return [details autorelease];
29 static CookiePromptContentDetailsAdapter* CreateCookieTestContent(
30     BOOL canEditExpiration) {
31   CocoaCookieDetails* details = CreateTestCookieDetails(canEditExpiration);
32   return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details]
33       autorelease];
36 static CocoaCookieDetails* CreateTestDatabaseDetails() {
37   std::string domain("chromium.org");
38   base::string16 name(base::SysNSStringToUTF16(@"wicked_name"));
39   base::string16 desc(base::SysNSStringToUTF16(@"wicked_desc"));
40   CocoaCookieDetails* details = [CocoaCookieDetails alloc];
41   [details initWithDatabase:domain
42                databaseName:name
43         databaseDescription:desc
44                    fileSize:2222];
45   return [details autorelease];
48 static CookiePromptContentDetailsAdapter* CreateDatabaseTestContent() {
49   CocoaCookieDetails* details = CreateTestDatabaseDetails();
50   return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details]
51           autorelease];
54 TEST_F(CookieDetailsViewControllerTest, Create) {
55   base::scoped_nsobject<CookieDetailsViewController> detailsViewController(
56       [[CookieDetailsViewController alloc] init]);
59 TEST_F(CookieDetailsViewControllerTest, ShrinkToFit) {
60   base::scoped_nsobject<CookieDetailsViewController> detailsViewController(
61       [[CookieDetailsViewController alloc] init]);
62   base::scoped_nsobject<CookiePromptContentDetailsAdapter> adapter(
63       [CreateDatabaseTestContent() retain]);
64   [detailsViewController.get() setContentObject:adapter.get()];
65   NSRect beforeFrame = [[detailsViewController.get() view] frame];
66   [detailsViewController.get() shrinkViewToFit];
67   NSRect afterFrame = [[detailsViewController.get() view] frame];
69   EXPECT_TRUE(afterFrame.size.height < beforeFrame.size.width);
72 TEST_F(CookieDetailsViewControllerTest, ExpirationEditability) {
73   base::scoped_nsobject<CookieDetailsViewController> detailsViewController(
74       [[CookieDetailsViewController alloc] init]);
75   [detailsViewController view];
76   base::scoped_nsobject<CookiePromptContentDetailsAdapter> adapter(
77       [CreateCookieTestContent(YES) retain]);
78   [detailsViewController.get() setContentObject:adapter.get()];
80   EXPECT_FALSE([detailsViewController.get() hasExpiration]);
81   [detailsViewController.get() setCookieHasExplicitExpiration:adapter.get()];
82   EXPECT_TRUE([detailsViewController.get() hasExpiration]);
83   [detailsViewController.get()
84       setCookieDoesntHaveExplicitExpiration:adapter.get()];
85   EXPECT_FALSE([detailsViewController.get() hasExpiration]);
88 }  // namespace