• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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.
4
5#import "chrome/browser/ui/cocoa/applescript/bookmark_applescript_utils_unittest.h"
6
7#include "chrome/browser/bookmarks/bookmark_model.h"
8
9@implementation FakeAppDelegate
10
11@synthesize helper = helper_;
12
13- (Profile*)defaultProfile {
14  if (!helper_)
15    return NULL;
16  return helper_->profile();
17}
18@end
19
20// Represents the current fake command that is executing.
21static FakeScriptCommand* kFakeCurrentCommand;
22
23@implementation FakeScriptCommand
24
25- (id)init {
26  if ((self = [super init])) {
27    originalMethod_ = class_getClassMethod([NSScriptCommand class],
28                                           @selector(currentCommand));
29    alternateMethod_ = class_getClassMethod([self class],
30                                            @selector(currentCommand));
31    method_exchangeImplementations(originalMethod_, alternateMethod_);
32    kFakeCurrentCommand = self;
33  }
34  return self;
35}
36
37+ (NSScriptCommand*)currentCommand {
38  return kFakeCurrentCommand;
39}
40
41- (void)dealloc {
42  method_exchangeImplementations(originalMethod_, alternateMethod_);
43  kFakeCurrentCommand = nil;
44  [super dealloc];
45}
46
47@end
48
49BookmarkAppleScriptTest::BookmarkAppleScriptTest() {
50  appDelegate_.reset([[FakeAppDelegate alloc] init]);
51  [appDelegate_.get() setHelper:&helper_];
52  DCHECK([NSApp delegate] == nil);
53  [NSApp setDelegate:appDelegate_];
54  const BookmarkNode* root = model().GetBookmarkBarNode();
55  const std::string modelString("a f1:[ b d c ] d f2:[ e f g ] h ");
56  model_test_utils::AddNodesFromModelString(model(), root, modelString);
57  bookmarkBar_.reset([[BookmarkFolderAppleScript alloc]
58      initWithBookmarkNode:model().GetBookmarkBarNode()]);
59}
60
61BookmarkAppleScriptTest::~BookmarkAppleScriptTest() {
62  [NSApp setDelegate:nil];
63}
64
65BookmarkModel& BookmarkAppleScriptTest::model() {
66  return *helper_.profile()->GetBookmarkModel();
67}
68