summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm39
-rw-r--r--chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm2
-rw-r--r--chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm107
-rw-r--r--chrome/browser/cocoa/applescript/examples/app_info.applescript9
-rw-r--r--chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript23
-rw-r--r--chrome/browser/cocoa/applescript/examples/quit_app.applescript8
-rw-r--r--chrome/browser/cocoa/applescript/examples/tab_navigation.applescript13
-rw-r--r--chrome/browser/cocoa/applescript/examples/window_creation.applescript10
-rw-r--r--chrome/browser/cocoa/applescript/examples/window_operations.applescript22
-rw-r--r--chrome/browser/cocoa/applescript/scripting.sdef11
-rw-r--r--chrome/browser/cocoa/applescript/window_applescript.mm5
-rw-r--r--chrome/browser/cocoa/applescript/window_applescript_test.mm10
-rw-r--r--chrome/chrome_tests.gypi1
13 files changed, 218 insertions, 42 deletions
diff --git a/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm b/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm
index f0f7d10..17a0b6a9 100644
--- a/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm
+++ b/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm
@@ -23,19 +23,17 @@ namespace {
// Test all the bookmark folders within.
TEST_F(BookmarkFolderAppleScriptTest, BookmarkFolders) {
NSArray* bookmarkFolders = [bookmarkBar_.get() bookmarkFolders];
- BookmarkFolderAppleScript* folder1 = [bookmarkFolders objectAtIndex:0];
- BookmarkFolderAppleScript* folder2 = [bookmarkFolders objectAtIndex:1];
EXPECT_EQ(2U, [bookmarkFolders count]);
- EXPECT_NSEQ(@"f1", [folder1 title]);
- EXPECT_NSEQ(@"f2", [folder2 title]);
- EXPECT_EQ([folder1 container], bookmarkBar_.get());
- EXPECT_EQ([folder2 container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
- [folder1 containerProperty]);
- EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
- [folder2 containerProperty]);
+ EXPECT_NSEQ(@"f1", [[bookmarkFolders objectAtIndex:0] title]);
+ EXPECT_NSEQ(@"f2", [[bookmarkFolders objectAtIndex:1] title]);
+
+ for (BookmarkFolderAppleScript* bookmarkFolder in bookmarkFolders) {
+ EXPECT_EQ([bookmarkFolder container], bookmarkBar_.get());
+ EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
+ [bookmarkFolder containerProperty]);
+ }
}
// Insert a new bookmark folder.
@@ -92,21 +90,18 @@ TEST_F(BookmarkFolderAppleScriptTest, DeleteBookmarkFolders) {
// Test all the bookmark items within.
TEST_F(BookmarkFolderAppleScriptTest, BookmarkItems) {
NSArray* bookmarkItems = [bookmarkBar_.get() bookmarkItems];
- BookmarkItemAppleScript* item1 = [bookmarkItems objectAtIndex:0];
- BookmarkItemAppleScript* item2 = [bookmarkItems objectAtIndex:1];
- BookmarkItemAppleScript* item3 = [bookmarkItems objectAtIndex:2];
EXPECT_EQ(3U, [bookmarkItems count]);
- EXPECT_NSEQ(@"a", [item1 title]);
- EXPECT_NSEQ(@"d", [item2 title]);
- EXPECT_NSEQ(@"h", [item3 title]);
- EXPECT_EQ([item1 container], bookmarkBar_.get());
- EXPECT_EQ([item2 container], bookmarkBar_.get());
- EXPECT_EQ([item3 container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty, [item1 containerProperty]);
- EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty, [item2 containerProperty]);
- EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty, [item3 containerProperty]);
+ EXPECT_NSEQ(@"a", [[bookmarkItems objectAtIndex:0] title]);
+ EXPECT_NSEQ(@"d", [[bookmarkItems objectAtIndex:1] title]);
+ EXPECT_NSEQ(@"h", [[bookmarkItems objectAtIndex:2] title]);
+
+ for (BookmarkItemAppleScript* bookmarkItem in bookmarkItems) {
+ EXPECT_EQ([bookmarkItem container], bookmarkBar_.get());
+ EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty,
+ [bookmarkItem containerProperty]);
+ }
}
// Insert a new bookmark item.
diff --git a/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm b/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm
index f01a318..1ac4165 100644
--- a/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm
+++ b/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm
@@ -29,6 +29,8 @@
scoped_nsobject<WindowAppleScript> window(
[[WindowAppleScript alloc] initWithBrowser:*browserIterator]);
+ [window setContainer:NSApp
+ property:AppleScript::kWindowsProperty];
[appleScriptWindows addObject:window];
}
// Windows sorted by their index value, which is obtained by calling
diff --git a/chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm b/chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm
new file mode 100644
index 0000000..2825ef2
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm
@@ -0,0 +1,107 @@
+// 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.
+
+#import <Cocoa/Cocoa.h>
+
+#include "chrome/browser/browser.h"
+#import "chrome/browser/cocoa/applescript/browsercrapplication+applescript.h"
+#import "chrome/browser/cocoa/applescript/constants_applescript.h"
+#import "chrome/browser/cocoa/applescript/window_applescript.h"
+#include "chrome/browser/profile.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gtest_mac.h"
+
+typedef InProcessBrowserTest BrowserCrApplicationAppleScriptTest;
+
+// Create windows of different |Type|.
+IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, Creation) {
+ // Create additional |Browser*| objects of different type.
+ Profile* profile = browser()->profile();
+ Browser* b1 = Browser::CreateForPopup(profile);
+ Browser* b2 = Browser::CreateForApp("", NULL, profile, true);
+ Browser* b3 = Browser::CreateForApp("", NULL, profile, false);
+
+ EXPECT_EQ(4U, [[NSApp appleScriptWindows] count]);
+ for (WindowAppleScript* window in [NSApp appleScriptWindows]) {
+ EXPECT_NSEQ(AppleScript::kWindowsProperty,
+ [window containerProperty]);
+ EXPECT_NSEQ(NSApp, [window container]);
+ }
+
+ // Close the additional browsers.
+ b1->CloseAllTabs();
+ b2->CloseAllTabs();
+ b3->CloseAllTabs();
+}
+
+// Insert a new window.
+IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, InsertWindow) {
+ // Emulate what applescript would do when creating a new window.
+ // Emulate a script like |set var to make new window with properties
+ // {visible:false}|.
+ scoped_nsobject<WindowAppleScript> aWindow([[WindowAppleScript alloc] init]);
+ scoped_nsobject<NSNumber> var([[aWindow.get() uniqueID] copy]);
+ [aWindow.get() setValue:[NSNumber numberWithBool:YES] forKey:@"isVisible"];
+
+ [NSApp insertInAppleScriptWindows:aWindow.get()];
+
+ // Represents the window after it is added.
+ WindowAppleScript* window = [[NSApp appleScriptWindows] objectAtIndex:0];
+ EXPECT_NSEQ([NSNumber numberWithBool:YES],
+ [aWindow.get() valueForKey:@"isVisible"]);
+ EXPECT_EQ([window container], NSApp);
+ EXPECT_NSEQ(AppleScript::kWindowsProperty,
+ [window containerProperty]);
+ EXPECT_NSEQ(var, [window uniqueID]);
+}
+
+// Inserting and deleting windows.
+IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest,
+ InsertAndDeleteWindows) {
+ scoped_nsobject<WindowAppleScript> aWindow;
+ int count;
+ // Create a bunch of windows.
+ for (int i = 0; i < 5; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ aWindow.reset([[WindowAppleScript alloc] init]);
+ [NSApp insertInAppleScriptWindows:aWindow.get()];
+ }
+ count = 3 * i + 4;
+ EXPECT_EQ(count, (int)[[NSApp appleScriptWindows] count]);
+ }
+
+ // Remove all the windows, just created.
+ count = (int)[[NSApp appleScriptWindows] count];
+ for (int i = 0; i < 5; ++i) {
+ for(int j = 0; j < 3; ++j) {
+ [NSApp removeFromAppleScriptWindowsAtIndex:0];
+ }
+ count = count - 3;
+ EXPECT_EQ(count, (int)[[NSApp appleScriptWindows] count]);
+ }
+}
+
+// Check for objectSpecifer of the root scripting object.
+IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, ObjectSpecifier) {
+ // Should always return nil to indicate its the root scripting object.
+ EXPECT_EQ(nil, [NSApp objectSpecifier]);
+}
+
+// Bookmark folders at the root level.
+IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, BookmarkFolders) {
+ NSArray* bookmarkFolders = [NSApp bookmarkFolders];
+ EXPECT_EQ(2U, [bookmarkFolders count]);
+
+ for (BookmarkFolderAppleScript* bookmarkFolder in bookmarkFolders) {
+ EXPECT_EQ(NSApp,
+ [bookmarkFolder container]);
+ EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
+ [bookmarkFolder containerProperty]);
+ }
+
+ EXPECT_NSEQ(@"Other Bookmarks", [[NSApp otherBookmarks] title]);
+ EXPECT_NSEQ(@"Bookmarks Bar", [[NSApp bookmarksBar] title]);
+}
+
diff --git a/chrome/browser/cocoa/applescript/examples/app_info.applescript b/chrome/browser/cocoa/applescript/examples/app_info.applescript
new file mode 100644
index 0000000..8377e14
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/examples/app_info.applescript
@@ -0,0 +1,9 @@
+-- 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.
+
+-- Gets basic information about the app.
+tell application "Chromium"
+ set var1 to name
+ set var2 to version
+end tell
diff --git a/chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript b/chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript
new file mode 100644
index 0000000..6e88268
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript
@@ -0,0 +1,23 @@
+-- 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.
+
+-- This script bookmarks the currently open tabs of a window.
+tell application "Chromium"
+ set url_list to {}
+ set title_list to {}
+ tell window 1
+ repeat with i from 1 to (count tabs)
+ set end of url_list to (URL of tab i)
+ set end of title_list to (title of tab i)
+ end repeat
+ end tell
+ tell bookmarks bar
+ set var to make new bookmark folder with properties {title:"New"}
+ tell var
+ repeat with i from 1 to (count url_list)
+ make new bookmark item with properties {URL:(item i of url_list), title:(item i of title_list)}
+ end repeat
+ end tell
+ end tell
+end tell \ No newline at end of file
diff --git a/chrome/browser/cocoa/applescript/examples/quit_app.applescript b/chrome/browser/cocoa/applescript/examples/quit_app.applescript
new file mode 100644
index 0000000..a6bdd1f
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/examples/quit_app.applescript
@@ -0,0 +1,8 @@
+-- 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.
+
+-- Quits the application, useful in cases where you want to schedule things.
+tell application "Chromium"
+ quit
+end tell
diff --git a/chrome/browser/cocoa/applescript/examples/tab_navigation.applescript b/chrome/browser/cocoa/applescript/examples/tab_navigation.applescript
new file mode 100644
index 0000000..2337869
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/examples/tab_navigation.applescript
@@ -0,0 +1,13 @@
+-- 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.
+
+tell application "Chromium"
+ tell window 1
+ -- creates a new tab and navigates to a particular URL.
+ make new tab with properties {URL:"http://google.com"}
+ -- Duplicate a tab.
+ set var to URL of tab 2
+ make new tab with properties {URL:var}
+ end tell
+end tell
diff --git a/chrome/browser/cocoa/applescript/examples/window_creation.applescript b/chrome/browser/cocoa/applescript/examples/window_creation.applescript
new file mode 100644
index 0000000..fc1486a
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/examples/window_creation.applescript
@@ -0,0 +1,10 @@
+-- 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.
+
+-- creates 2 windows, one in normal mode and another in incognito mode.
+tell application "Chromium"
+ make new window
+ make new window with properties {mode:"incognito"}
+ count windows -- count how many windows are currently open.
+end tell
diff --git a/chrome/browser/cocoa/applescript/examples/window_operations.applescript b/chrome/browser/cocoa/applescript/examples/window_operations.applescript
new file mode 100644
index 0000000..90a0288
--- /dev/null
+++ b/chrome/browser/cocoa/applescript/examples/window_operations.applescript
@@ -0,0 +1,22 @@
+-- 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.
+
+-- Contains usage of common window operations.
+tell application "Chromium"
+ get URL of active tab of window 1 -- The URL currently being seen.
+
+ set minimized of window 1 to true -- Minimizes a window.
+ set minimized of window 1 to false -- Maximizes a window.
+
+ get mode of window 1
+ -- Checks if a window is in |normal mode| or |incognito mode|
+
+ set visible of window 1 to true -- Hides a window.
+ set visible of window 1 to false -- UnHides a window.
+
+ -- Open multiple tabs.
+ set active tab index of window 1 to 2 -- Selects the second tab.
+
+
+end tell
diff --git a/chrome/browser/cocoa/applescript/scripting.sdef b/chrome/browser/cocoa/applescript/scripting.sdef
index 6200f7f..a65ed4e 100644
--- a/chrome/browser/cocoa/applescript/scripting.sdef
+++ b/chrome/browser/cocoa/applescript/scripting.sdef
@@ -16,9 +16,6 @@
<cocoa key="isActive"/>
</property>
<property name="version" code="vers" description="The version of the application." type="text" access="r"/>
- <responds-to command="open">
- <cocoa method="handleOpenScriptCommand:"/>
- </responds-to>
<responds-to command="quit">
<cocoa method="handleQuitScriptCommand:"/>
</responds-to>
@@ -203,13 +200,13 @@
<responds-to command="redo">
<cocoa method="handlesRedoScriptCommand:"/>
</responds-to>
- <responds-to command="cut">
+ <responds-to command="cut selection">
<cocoa method="handlesCutScriptCommand:"/>
</responds-to>
- <responds-to command="copy">
+ <responds-to command="copy selection">
<cocoa method="handlesCopyScriptCommand:"/>
</responds-to>
- <responds-to command="paste">
+ <responds-to command="paste selection">
<cocoa method="handlesPasteScriptCommand:"/>
</responds-to>
<responds-to command="select all">
@@ -276,7 +273,7 @@
<command name="copy selection" code="CrSuCop " description="Copy text.">
<direct-parameter type="specifier"/>
</command>
- <command name="paste" code="CrSuPast" description="Paste text (If Possible).">
+ <command name="paste selection" code="CrSuPast" description="Paste text (If Possible).">
<direct-parameter type="specifier"/>
</command>
<command name="undo" code="CrSuUndo" description="Undo the last change.">
diff --git a/chrome/browser/cocoa/applescript/window_applescript.mm b/chrome/browser/cocoa/applescript/window_applescript.mm
index 6fcb10b..cb2eb81 100644
--- a/chrome/browser/cocoa/applescript/window_applescript.mm
+++ b/chrome/browser/cocoa/applescript/window_applescript.mm
@@ -71,9 +71,6 @@
scoped_nsobject<NSNumber> numID(
[[NSNumber alloc] initWithInt:browser_->session_id().id()]);
[self setUniqueID:numID];
- [self setContainer:
- (BrowserCrApplication*)[BrowserCrApplication sharedApplication]
- property:AppleScript::kWindowsProperty];
}
return self;
}
@@ -92,8 +89,6 @@
scoped_nsobject<NSNumber> numID(
[[NSNumber alloc] initWithInt:browser_->session_id().id()]);
[self setUniqueID:numID];
- [self setContainer:NSApp
- property:AppleScript::kWindowsProperty];
}
return self;
}
diff --git a/chrome/browser/cocoa/applescript/window_applescript_test.mm b/chrome/browser/cocoa/applescript/window_applescript_test.mm
index 6b4425a..809afb3 100644
--- a/chrome/browser/cocoa/applescript/window_applescript_test.mm
+++ b/chrome/browser/cocoa/applescript/window_applescript_test.mm
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#import <Cocoa/Cocoa.h>
+
#import "base/scoped_nsobject.h"
#include "base/sys_string_conversions.h"
#import "chrome/browser/app_controller_mac.h"
@@ -42,10 +44,6 @@ IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithProfile) {
[[WindowAppleScript alloc] initWithProfile:defaultProfile]);
EXPECT_TRUE(aWindow.get());
EXPECT_TRUE([aWindow.get() uniqueID]);
- EXPECT_EQ([aWindow.get() container],
- [BrowserCrApplication sharedApplication]);
- EXPECT_NSEQ(AppleScript::kWindowsProperty,
- [aWindow.get() containerProperty]);
}
// Create a window with no |Browser*|.
@@ -61,10 +59,6 @@ IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithBrowser) {
[[WindowAppleScript alloc] initWithBrowser:browser()]);
EXPECT_TRUE(aWindow.get());
EXPECT_TRUE([aWindow.get() uniqueID]);
- EXPECT_EQ([aWindow.get() container],
- [BrowserCrApplication sharedApplication]);
- EXPECT_NSEQ(AppleScript::kWindowsProperty,
- [aWindow.get() containerProperty]);
}
// Tabs within the window.
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index a6e49b0..c14f8bd 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1546,6 +1546,7 @@
'browser/chromeos/tab_closeable_state_watcher_browsertest.cc',
'browser/chromeos/update_browsertest.cc',
'browser/cocoa/view_id_util_browsertest.mm',
+ 'browser/cocoa/applescript/browsercrapplication+applescript_test.mm',
'browser/cocoa/applescript/window_applescript_test.mm',
'browser/crash_recovery_browsertest.cc',
'browser/device_orientation/device_orientation_browsertest.cc',