| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_ | 5 #ifndef CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_ |
| 6 #define CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_ | 6 #define CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_ |
| 7 | 7 |
| 8 #import <objc/objc-runtime.h> | 8 #import <objc/objc-runtime.h> |
| 9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #include "base/scoped_nsobject.h" | 11 #include "base/scoped_nsobject.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #import "chrome/browser/app_controller_mac.h" | 13 #import "chrome/browser/app_controller_mac.h" |
| 14 #import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h" | 14 #import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h" |
| 15 #include "chrome/browser/cocoa/browser_test_helper.h" | 15 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 16 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 16 #include "chrome/browser/cocoa/cocoa_test_helper.h" |
| 17 #include "chrome/test/model_test_utils.h" | 17 #include "chrome/test/model_test_utils.h" |
| 18 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 19 | 19 |
| 20 class BookmarkModel; |
| 21 |
| 20 // The fake object that acts as our app's delegate, useful for testing purposes. | 22 // The fake object that acts as our app's delegate, useful for testing purposes. |
| 21 @interface FakeAppDelegate : AppController { | 23 @interface FakeAppDelegate : AppController { |
| 22 @public | 24 @public |
| 23 BrowserTestHelper* helper_; // weak. | 25 BrowserTestHelper* helper_; // weak. |
| 24 } | 26 } |
| 25 @property (nonatomic) BrowserTestHelper* helper; | 27 @property (nonatomic) BrowserTestHelper* helper; |
| 26 // Return the |TestingProfile*| which is used for testing. | 28 // Return the |TestingProfile*| which is used for testing. |
| 27 - (Profile*)defaultProfile; | 29 - (Profile*)defaultProfile; |
| 28 @end | 30 @end |
| 29 | 31 |
| 30 | 32 |
| 31 // Used to emulate an active running script, useful for testing purposes. | 33 // Used to emulate an active running script, useful for testing purposes. |
| 32 @interface FakeScriptCommand : NSScriptCommand { | 34 @interface FakeScriptCommand : NSScriptCommand { |
| 33 Method originalMethod_; | 35 Method originalMethod_; |
| 34 Method alternateMethod_; | 36 Method alternateMethod_; |
| 35 } | 37 } |
| 36 @end | 38 @end |
| 37 | 39 |
| 38 | 40 |
| 39 // The base class for all our bookmark releated unit tests. | 41 // The base class for all our bookmark releated unit tests. |
| 40 class BookmarkAppleScriptTest : public CocoaTest { | 42 class BookmarkAppleScriptTest : public CocoaTest { |
| 41 public: | 43 public: |
| 42 BookmarkAppleScriptTest() { | 44 BookmarkAppleScriptTest(); |
| 43 appDelegate_.reset([[FakeAppDelegate alloc] init]); | |
| 44 [appDelegate_.get() setHelper:&helper_]; | |
| 45 [NSApp setDelegate:appDelegate_]; | |
| 46 const BookmarkNode* root = model().GetBookmarkBarNode(); | |
| 47 const std::wstring modelString(L"a f1:[ b d c ] d f2:[ e f g ] h "); | |
| 48 model_test_utils::AddNodesFromModelString(model(), root, modelString); | |
| 49 bookmarkBar_.reset([[BookmarkFolderAppleScript alloc] | |
| 50 initWithBookmarkNode:model().GetBookmarkBarNode()]); | |
| 51 } | |
| 52 private: | 45 private: |
| 53 BrowserTestHelper helper_; | 46 BrowserTestHelper helper_; |
| 54 scoped_nsobject<FakeAppDelegate> appDelegate_; | 47 scoped_nsobject<FakeAppDelegate> appDelegate_; |
| 55 protected: | 48 protected: |
| 56 scoped_nsobject<BookmarkFolderAppleScript> bookmarkBar_; | 49 scoped_nsobject<BookmarkFolderAppleScript> bookmarkBar_; |
| 57 BookmarkModel& model() { | 50 BookmarkModel& model(); |
| 58 return *helper_.profile()->GetBookmarkModel(); | |
| 59 } | |
| 60 }; | 51 }; |
| 61 | 52 |
| 62 #endif | 53 #endif |
| 63 // CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_ | 54 // CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_ |
| OLD | NEW |