Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / applescript / bookmark_applescript_utils_unittest.mm
blob5b218989e04f10bc890defca454a2270dbf5dced
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_factory.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "components/bookmarks/browser/bookmark_model.h"
10 #include "components/bookmarks/test/bookmark_test_helpers.h"
12 using bookmarks::BookmarkModel;
13 using bookmarks::BookmarkNode;
15 @implementation FakeAppDelegate
17 @synthesize test = test_;
19 - (Profile*)lastProfile {
20   if (!test_)
21     return NULL;
22   return test_->profile();
24 @end
26 // Represents the current fake command that is executing.
27 static FakeScriptCommand* kFakeCurrentCommand;
29 @implementation FakeScriptCommand
31 - (id)init {
32   if ((self = [super init])) {
33     originalMethod_ = class_getClassMethod([NSScriptCommand class],
34                                            @selector(currentCommand));
35     alternateMethod_ = class_getClassMethod([self class],
36                                             @selector(currentCommand));
37     method_exchangeImplementations(originalMethod_, alternateMethod_);
38     kFakeCurrentCommand = self;
39   }
40   return self;
43 + (NSScriptCommand*)currentCommand {
44   return kFakeCurrentCommand;
47 - (void)dealloc {
48   method_exchangeImplementations(originalMethod_, alternateMethod_);
49   kFakeCurrentCommand = nil;
50   [super dealloc];
53 @end
55 BookmarkAppleScriptTest::BookmarkAppleScriptTest() {
58 BookmarkAppleScriptTest::~BookmarkAppleScriptTest() {
59   [NSApp setDelegate:nil];
62 void BookmarkAppleScriptTest::SetUp() {
63   CocoaProfileTest::SetUp();
64   ASSERT_TRUE(profile());
66   appDelegate_.reset([[FakeAppDelegate alloc] init]);
67   [appDelegate_.get() setTest:this];
68   DCHECK([NSApp delegate] == nil);
69   [NSApp setDelegate:appDelegate_];
70   BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
71   const BookmarkNode* root = model->bookmark_bar_node();
72   const std::string modelString("a f1:[ b d c ] d f2:[ e f g ] h ");
73   bookmarks::test::AddNodesFromModelString(model, root, modelString);
74   bookmarkBar_.reset([[BookmarkFolderAppleScript alloc]
75       initWithBookmarkNode:model->bookmark_bar_node()]);