diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 12:08:16 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 12:08:16 +0000 |
commit | 00bbf288f956c321b02c98ba5046c1728b248934 (patch) | |
tree | 3aaaee6ca2b24e686ab275c149ec58cb9351cd80 /chrome | |
parent | 946d4cb34091f76050d04d0be5c71e3f0bee95da (diff) | |
download | chromium_src-00bbf288f956c321b02c98ba5046c1728b248934.zip chromium_src-00bbf288f956c321b02c98ba5046c1728b248934.tar.gz chromium_src-00bbf288f956c321b02c98ba5046c1728b248934.tar.bz2 |
Mac: Enable WebAppShortcutCreatorTest.CreateShortcut unit test
* Mock out code to reveal generated app bundle in Finder.
* Change how we fill in the template plist to a variable substitution model.
* Clean app_mode-Info.plist to remove unneeded keys.
BUG=112651
TEST=WebAppShortcutCreatorTest.CreateShortcut should pass.
Review URL: http://codereview.chromium.org/9426030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/app_mode-Info.plist | 6 | ||||
-rw-r--r-- | chrome/app/app_mode_loader_mac.mm | 3 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.h | 4 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.mm | 66 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac_unittest.mm | 10 | ||||
-rw-r--r-- | chrome/common/mac/app_mode_common.h | 17 | ||||
-rw-r--r-- | chrome/common/mac/app_mode_common.mm | 5 |
7 files changed, 71 insertions, 40 deletions
diff --git a/chrome/app/app_mode-Info.plist b/chrome/app/app_mode-Info.plist index 1603382..f89e0bc 100644 --- a/chrome/app/app_mode-Info.plist +++ b/chrome/app/app_mode-Info.plist @@ -4,8 +4,6 @@ <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> - <key>CFBundleDisplayName</key> - <string>@APP_MODE_SHORTCUT_SHORT_NAME@</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleExecutable</key> @@ -22,12 +20,12 @@ <string>APPL</string> <key>CrAppModeShortcutID</key> <string>@APP_MODE_SHORTCUT_ID@</string> - <key>CrAppModeShortcutShortName</key> - <string>@APP_MODE_SHORTCUT_SHORT_NAME@</string> <key>CrAppModeShortcutName</key> <string>@APP_MODE_SHORTCUT_NAME@</string> <key>CrAppModeShortcutURL</key> <string>@APP_MODE_SHORTCUT_URL@</string> + <key>CrBundleIdentifier</key> + <string>@APP_MODE_BROWSER_BUNDLE_ID@</string> <key>LSFileQuarantineEnabled</key> <true/> <key>LSMinimumSystemVersion</key> diff --git a/chrome/app/app_mode_loader_mac.mm b/chrome/app/app_mode_loader_mac.mm index a691b15..e8242f0 100644 --- a/chrome/app/app_mode_loader_mac.mm +++ b/chrome/app/app_mode_loader_mac.mm @@ -86,9 +86,6 @@ void LoadFramework(void** cr_dylib, app_mode::ChromeAppModeInfo* info) { [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); CHECK(info->app_mode_id.size()) << "couldn't get app shortcut ID"; - info->app_mode_short_name = SysNSStringToUTF16( - [info_plist objectForKey:app_mode::kCrAppModeShortcutShortNameKey]); - info->app_mode_name = SysNSStringToUTF16( [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); diff --git a/chrome/browser/web_applications/web_app_mac.h b/chrome/browser/web_applications/web_app_mac.h index 968bb8c..c81250e 100644 --- a/chrome/browser/web_applications/web_app_mac.h +++ b/chrome/browser/web_applications/web_app_mac.h @@ -65,6 +65,10 @@ class WebAppShortcutCreator { // be used for creating the app bundle. NSString* GetBundleIdentifier(NSDictionary* plist) const; + // Show the bundle we just generated in the Finder. + virtual void RevealGeneratedBundleInFinder( + const FilePath& generated_bundle) const; + // Information about the app. ShellIntegration::ShortcutInfo info_; diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index 33adce3..004f8d4 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -80,9 +80,8 @@ bool WebAppShortcutCreator::CreateShortcut() { return false; } - [[NSWorkspace sharedWorkspace] - selectFile:base::mac::FilePathToNSString(dst_path) - inFileViewerRootedAtPath:nil]; + RevealGeneratedBundleInFinder(dst_path); + return true; } @@ -108,24 +107,46 @@ FilePath WebAppShortcutCreator::GetDestinationPath( bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const { NSString* plist_path = base::mac::FilePathToNSString( app_path.Append("Contents").Append("Info.plist")); - NSMutableDictionary* dict = + + NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id); + NSString* extension_title = base::SysUTF16ToNSString(info_.title); + NSString* extension_url = base::SysUTF8ToNSString(info_.url.spec()); + NSString* chrome_bundle_id = base::SysUTF16ToNSString(chrome_bundle_id_); + NSDictionary* replacement_dict = + [NSDictionary dictionaryWithObjectsAndKeys: + extension_id, app_mode::kShortcutIdPlaceholder, + extension_title, app_mode::kShortcutNamePlaceholder, + extension_url, app_mode::kShortcutURLPlaceholder, + chrome_bundle_id, app_mode::kShortcutBrowserBundleIDPlaceholder, + nil]; + + NSMutableDictionary* plist = [NSMutableDictionary dictionaryWithContentsOfFile:plist_path]; + NSArray* keys = [plist allKeys]; + + // 1. Fill in variables. + for (id key in keys) { + NSString* value = [plist valueForKey:key]; + if (![value isKindOfClass:[NSString class]] || [value length] < 2) + continue; + + // Remove leading and trailing '@'s. + NSString* variable = + [value substringWithRange:NSMakeRange(1, [value length] - 2)]; - [dict setObject:GetBundleIdentifier(dict) - forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; - [dict setObject:base::SysUTF8ToNSString(info_.extension_id) - forKey:app_mode::kCrAppModeShortcutIDKey]; - [dict setObject:base::SysUTF16ToNSString(info_.title) - forKey:app_mode::kCrAppModeShortcutNameKey]; - [dict setObject:base::SysUTF8ToNSString(info_.url.spec()) - forKey:app_mode::kCrAppModeShortcutURLKey]; - [dict setObject:base::mac::FilePathToNSString(user_data_dir_) - forKey:app_mode::kCrAppModeUserDataDirKey]; - [dict setObject:base::mac::FilePathToNSString(info_.extension_path) - forKey:app_mode::kCrAppModeExtensionPathKey]; - [dict setObject:base::SysUTF16ToNSString(chrome_bundle_id_) - forKey:app_mode::kBrowserBundleIDKey]; - return [dict writeToFile:plist_path atomically:YES]; + NSString* substitution = [replacement_dict valueForKey:variable]; + if (substitution) + [plist setObject:substitution forKey:key]; + } + + // 2. Fill in other values. + [plist setObject:GetBundleIdentifier(plist) + forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; + [plist setObject:base::mac::FilePathToNSString(user_data_dir_) + forKey:app_mode::kCrAppModeUserDataDirKey]; + [plist setObject:base::mac::FilePathToNSString(info_.extension_path) + forKey:app_mode::kCrAppModeExtensionPathKey]; + return [plist writeToFile:plist_path atomically:YES]; } bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { @@ -173,6 +194,13 @@ NSString* WebAppShortcutCreator::GetBundleIdentifier(NSDictionary* plist) const return bundle_id; } +void WebAppShortcutCreator::RevealGeneratedBundleInFinder( + const FilePath& generated_bundle) const { + [[NSWorkspace sharedWorkspace] + selectFile:base::mac::FilePathToNSString(generated_bundle) + inFileViewerRootedAtPath:nil]; +} + } // namespace namespace web_app { diff --git a/chrome/browser/web_applications/web_app_mac_unittest.mm b/chrome/browser/web_applications/web_app_mac_unittest.mm index fa11eaa..a2b78dc 100644 --- a/chrome/browser/web_applications/web_app_mac_unittest.mm +++ b/chrome/browser/web_applications/web_app_mac_unittest.mm @@ -30,16 +30,18 @@ class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { public: explicit WebAppShortcutCreatorMock( const ShellIntegration::ShortcutInfo& shortcut_info) - : WebAppShortcutCreator(FilePath(), shortcut_info, + : WebAppShortcutCreator(FilePath("/fake/path"), shortcut_info, UTF8ToUTF16("fake.cfbundleidentifier")) { } MOCK_CONST_METHOD1(GetDestinationPath, FilePath(const FilePath&)); + MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder, void(const FilePath&)); }; ShellIntegration::ShortcutInfo GetShortcutInfo() { ShellIntegration::ShortcutInfo info; info.extension_id = "extension_id"; + info.extension_path = FilePath("/fake/extension/path"); info.title = ASCIIToUTF16("Shortcut Title"); info.url = GURL("http://example.com/"); return info; @@ -53,7 +55,7 @@ namespace web_app { // * The plist still isn't filled in correctly. // * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it // shouldn't be doing when run from a unit test. -TEST(WebAppShortcutCreatorTest, DISABLED_CreateShortcut) { +TEST(WebAppShortcutCreatorTest, CreateShortcut) { ScopedTempDir scoped_temp_dir; EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); FilePath dst_path = scoped_temp_dir.path().Append("a.app"); @@ -62,6 +64,8 @@ TEST(WebAppShortcutCreatorTest, DISABLED_CreateShortcut) { NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) .WillRepeatedly(Return(dst_path)); + EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); + EXPECT_TRUE(shortcut_creator.CreateShortcut()); EXPECT_TRUE(file_util::PathExists(dst_path)); @@ -86,7 +90,7 @@ TEST(WebAppShortcutCreatorTest, DISABLED_CreateShortcut) { } } -TEST(WebAppShortcutCreatorTest, DISABLED_CreateFailure) { +TEST(WebAppShortcutCreatorTest, CreateFailure) { NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) .WillRepeatedly(Return(FilePath("/non-existant/path/"))); diff --git a/chrome/common/mac/app_mode_common.h b/chrome/common/mac/app_mode_common.h index b8bc539..f0f3ad2 100644 --- a/chrome/common/mac/app_mode_common.h +++ b/chrome/common/mac/app_mode_common.h @@ -23,10 +23,7 @@ extern NSString* const kBrowserBundleIDKey; // Key for the shortcut ID. extern NSString* const kCrAppModeShortcutIDKey; -// Key for the app's shortcut name. -extern NSString* const kCrAppModeShortcutShortNameKey; - -// Key for the app's unrestricted name. +// Key for the app's name. extern NSString* const kCrAppModeShortcutNameKey; // Key for the app's URL. @@ -42,9 +39,12 @@ extern NSString* const kCrAppModeExtensionPathKey; // system using this key. extern NSString* const kLastRunAppBundlePathPrefsKey; -// Placeholder used in the Info.plist, meant to be replaced by the extension -// shortcut ID. -extern NSString* const kShortcutIdPlaceholder; +// Placeholders used in the app mode loader bundle' Info.plist: +extern NSString* const kShortcutIdPlaceholder; // Extension shortcut ID. +extern NSString* const kShortcutNamePlaceholder; // Extension name. +extern NSString* const kShortcutURLPlaceholder; +// Bundle ID of the Chrome browser bundle. +extern NSString* const kShortcutBrowserBundleIDPlaceholder; // Current major/minor version numbers of |ChromeAppModeInfo| (defined below). const unsigned kCurrentChromeAppModeInfoMajorVersion = 1; @@ -84,9 +84,6 @@ struct ChromeAppModeInfo { // safe for the file system. std::string app_mode_id; // Required: v1.0 - // Short (e.g., one-word) UTF8-encoded name for the shortcut. - string16 app_mode_short_name; // Optional: v1.0 - // Unrestricted (e.g., several-word) UTF8-encoded name for the shortcut. string16 app_mode_name; // Optional: v1.0 diff --git a/chrome/common/mac/app_mode_common.mm b/chrome/common/mac/app_mode_common.mm index bb8c267..c6d5573 100644 --- a/chrome/common/mac/app_mode_common.mm +++ b/chrome/common/mac/app_mode_common.mm @@ -8,7 +8,6 @@ namespace app_mode { NSString* const kBrowserBundleIDKey = @"CrBundleIdentifier"; NSString* const kCrAppModeShortcutIDKey = @"CrAppModeShortcutID"; -NSString* const kCrAppModeShortcutShortNameKey = @"CrAppModeShortcutShortName"; NSString* const kCrAppModeShortcutNameKey = @"CrAppModeShortcutName"; NSString* const kCrAppModeShortcutURLKey = @"CrAppModeShortcutURL"; NSString* const kCrAppModeUserDataDirKey = @"CrAppModeUserDataDir"; @@ -17,6 +16,10 @@ NSString* const kCrAppModeExtensionPathKey = @"CrAppModeExtensionPath"; NSString* const kLastRunAppBundlePathPrefsKey = @"LastRunAppBundlePath"; NSString* const kShortcutIdPlaceholder = @"APP_MODE_SHORTCUT_ID"; +NSString* const kShortcutNamePlaceholder = @"APP_MODE_SHORTCUT_NAME"; +NSString* const kShortcutURLPlaceholder = @"APP_MODE_SHORTCUT_URL"; +NSString* const kShortcutBrowserBundleIDPlaceholder = + @"APP_MODE_BROWSER_BUNDLE_ID"; ChromeAppModeInfo::ChromeAppModeInfo() : major_version(0), |