Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / applescript / bookmark_applescript_utils_unittest.mm
blob8de23bf3bf6232f16a5c14f6f32a0a7d0df4e5aa
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 #import "chrome/browser/ui/cocoa/applescript/bookmark_applescript_utils_unittest.h"
7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
10 #include "chrome/test/base/testing_profile.h"
12 @implementation FakeAppDelegate
14 @synthesize test = test_;
16 - (Profile*)lastProfile {
17   if (!test_)
18     return NULL;
19   return test_->profile();
21 @end
23 // Represents the current fake command that is executing.
24 static FakeScriptCommand* kFakeCurrentCommand;
26 @implementation FakeScriptCommand
28 - (id)init {
29   if ((self = [super init])) {
30     originalMethod_ = class_getClassMethod([NSScriptCommand class],
31                                            @selector(currentCommand));
32     alternateMethod_ = class_getClassMethod([self class],
33                                             @selector(currentCommand));
34     method_exchangeImplementations(originalMethod_, alternateMethod_);
35     kFakeCurrentCommand = self;
36   }
37   return self;
40 + (NSScriptCommand*)currentCommand {
41   return kFakeCurrentCommand;
44 - (void)dealloc {
45   method_exchangeImplementations(originalMethod_, alternateMethod_);
46   kFakeCurrentCommand = nil;
47   [super dealloc];
50 @end
52 BookmarkAppleScriptTest::BookmarkAppleScriptTest() {
55 BookmarkAppleScriptTest::~BookmarkAppleScriptTest() {
56   [NSApp setDelegate:nil];
59 void BookmarkAppleScriptTest::SetUp() {
60   CocoaProfileTest::SetUp();
61   ASSERT_TRUE(profile());
63   appDelegate_.reset([[FakeAppDelegate alloc] init]);
64   [appDelegate_.get() setTest:this];
65   DCHECK([NSApp delegate] == nil);
66   [NSApp setDelegate:appDelegate_];
67   BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
68   const BookmarkNode* root = model->bookmark_bar_node();
69   const std::string modelString("a f1:[ b d c ] d f2:[ e f g ] h ");
70   test::AddNodesFromModelString(model, root, modelString);
71   bookmarkBar_.reset([[BookmarkFolderAppleScript alloc]
72       initWithBookmarkNode:model->bookmark_bar_node()]);