summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm
blob: a1d6a6783643bfb43c6cf02c2e3d517aab34f3d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// 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/cocoa_test_helper.h"
#include "chrome/browser/cocoa/cookie_details_view_controller.h"
#include "chrome/browser/cookie_modal_dialog.h"

// Mock apapter that returns dummy values for the details view
@interface MockCookieDetailsViewContentAdapter : NSObject {
 @private
  // The type of fake cookie data to display
  CookiePromptModalDialog::DialogType promptType_;
}

- (id)initWithType:(CookiePromptModalDialog::DialogType)type;

// 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;

@end

@implementation MockCookieDetailsViewContentAdapter

- (id)initWithType:(CookiePromptModalDialog::DialogType)type {
  if ((self = [super init])) {
    promptType_ = type;
  }
  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 @"dummyName";
}

- (NSString*)content {
  return @"dummyContent";
}

- (NSString*)domain {
  return @"dummyDomain";
}

- (NSString*)path {
  return @"dummyPath";
}

- (NSString*)sendFor {
  return @"dummySendFor";
}

- (NSString*)created {
  return @"dummyCreated";
}

- (NSString*)expires {
  return @"dummyExpires";
}

- (NSString*)fileSize {
  return @"dummyFileSize";
}

- (NSString*)lastModified {
  return @"dummyLastModified";
}

- (NSString*)databaseDescription {
  return @"dummyDatabaseDescription";
}

- (NSString*)localStorageKey {
  return @"dummyLocalStorageKey";
}

- (NSString*)localStorageValue {
  return @"dummyLocalStorageValue";
}

@end

namespace {

class CookieDetailsViewControllerTest : public CocoaTest {
};

TEST_F(CookieDetailsViewControllerTest, Create) {
  scoped_nsobject<CookieDetailsViewController> detailsViewController;
  detailsViewController.reset([[CookieDetailsViewController alloc] init]);
}

TEST_F(CookieDetailsViewControllerTest, ShrinkToFit) {
  scoped_nsobject<CookieDetailsViewController> detailsViewController;
  detailsViewController.reset([[CookieDetailsViewController alloc] init]);
  scoped_nsobject<MockCookieDetailsViewContentAdapter> mockAdapter;
  mockAdapter.reset([[MockCookieDetailsViewContentAdapter alloc]
      initWithType:CookiePromptModalDialog::DIALOG_TYPE_DATABASE]);
  [detailsViewController.get() setContentObject:mockAdapter.get()];
  NSRect beforeFrame = [[detailsViewController.get() view] frame];
  [detailsViewController.get() shrinkViewToFit];
  NSRect afterFrame = [[detailsViewController.get() view] frame];
  EXPECT_TRUE(afterFrame.size.height < beforeFrame.size.width);
}

}  // namespace