diff options
author | denisromanov@chromium.org <denisromanov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 16:40:55 +0000 |
---|---|---|
committer | denisromanov@chromium.org <denisromanov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 16:40:55 +0000 |
commit | f8cef98edf2ecc34d832cc983e97da78653540c3 (patch) | |
tree | 9c61814e0b2ad4eaf60ffcfad5f2afacbd4ae3eb /chrome | |
parent | 6ab685b2baa862d299123f5f62c2165e2be692a3 (diff) | |
download | chromium_src-f8cef98edf2ecc34d832cc983e97da78653540c3.zip chromium_src-f8cef98edf2ecc34d832cc983e97da78653540c3.tar.gz chromium_src-f8cef98edf2ecc34d832cc983e97da78653540c3.tar.bz2 |
Added implementation of partner services manifest parsing, unit test and sample manifest.
BUG=cros:3176
TEST=Run out/Debug/unit_tests
Review URL: http://codereview.chromium.org/2632004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 165 insertions, 30 deletions
diff --git a/chrome/browser/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc index 883313f..e0f5f32 100644 --- a/chrome/browser/chromeos/customization_document.cc +++ b/chrome/browser/chromeos/customization_document.cc @@ -64,6 +64,7 @@ bool CustomizationDocument::LoadManifestFromString( bool CustomizationDocument::ParseFromJsonValue(const DictionaryValue* root) { // Partner customization manifests share only one required field - // version string. + version_.clear(); bool result = root->GetString(kVersionAttr, &version_); return result && version_ == kAcceptedManifestVersion; } @@ -74,11 +75,16 @@ bool StartupCustomizationDocument::ParseFromJsonValue( const DictionaryValue* root) { if (!CustomizationDocument::ParseFromJsonValue(root)) return false; - // Rquired fields. + + // Required fields. + product_sku_.clear(); if (!root->GetString(kProductSkuAttr, &product_sku_)) return false; + // Optional fields. + initial_locale_.clear(); root->GetString(kInitialLocaleAttr, &initial_locale_); + std::string background_color_string; root->GetString(kBackgroundColorAttr, &background_color_string); if (!background_color_string.empty()) { @@ -90,7 +96,10 @@ bool StartupCustomizationDocument::ParseFromJsonValue( return false; } } + + registration_url_.clear(); root->GetString(kRegistrationUrlAttr, ®istration_url_); + ListValue* setup_content_value = NULL; root->GetList(kSetupContentAttr, &setup_content_value); if (setup_content_value != NULL) { @@ -111,6 +120,7 @@ bool StartupCustomizationDocument::ParseFromJsonValue( setup_content_[content_locale] = content; } } + return true; } @@ -128,8 +138,56 @@ const StartupCustomizationDocument::SetupContent* bool ServicesCustomizationDocument::ParseFromJsonValue( const DictionaryValue* root) { - return CustomizationDocument::ParseFromJsonValue(root); - // TODO(denisromanov): implement. + if (!CustomizationDocument::ParseFromJsonValue(root)) + return false; + + // Required app menu settings. + DictionaryValue* app_menu_value = NULL; + root->GetDictionary(kAppMenuAttr, &app_menu_value); + if (app_menu_value == NULL) + return false; + + app_menu_section_title_.clear(); + if (!app_menu_value->GetString(kSectionTitleAttr, + &app_menu_section_title_)) + return false; + app_menu_support_page_url_.clear(); + if (!app_menu_value->GetString(kSupportPageAttr, + &app_menu_support_page_url_)) + return false; + + ListValue* web_apps_value = NULL; + app_menu_value->GetList(kWebAppsAttr, &web_apps_value); + if (!ParseStringListFromJsonValue(web_apps_value, &web_apps_)) + return false; + + ListValue* extensions_value = NULL; + app_menu_value->GetList(kExtensionsAttr, &extensions_value); + if (!ParseStringListFromJsonValue(extensions_value, &extensions_)) + return false; + + // Optional fields. + initial_start_page_url_.clear(); + root->GetString(kInitialStartPageAttr, &initial_start_page_url_); + + return true; +} + +bool ServicesCustomizationDocument::ParseStringListFromJsonValue( + const ListValue* list_value, + StringList* string_list) { + if (list_value == NULL || string_list == NULL) + return false; + DCHECK(list_value->GetType() == Value::TYPE_LIST); + string_list->clear(); + for (ListValue::const_iterator iter = list_value->begin(); + iter != list_value->end(); + ++iter) { + std::string url; + if ((*iter)->GetAsString(&url)) + string_list->push_back(url); + } + return true; } } // namespace chromeos diff --git a/chrome/browser/chromeos/customization_document.h b/chrome/browser/chromeos/customization_document.h index ce9d68a..a46d847 100644 --- a/chrome/browser/chromeos/customization_document.h +++ b/chrome/browser/chromeos/customization_document.h @@ -5,19 +5,22 @@ #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ -#include <list> #include <map> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "third_party/skia/include/core/SkColor.h" class DictionaryValue; +class ListValue; class FilePath; namespace chromeos { +// Base class for OEM customization document classes. + class CustomizationDocument { public: CustomizationDocument() {} @@ -38,6 +41,8 @@ class CustomizationDocument { DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); }; +// OEM startup customization document class. + class StartupCustomizationDocument : public CustomizationDocument { public: struct SetupContent { @@ -85,24 +90,43 @@ class StartupCustomizationDocument : public CustomizationDocument { DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); }; +// OEM services customization document class. + class ServicesCustomizationDocument : public CustomizationDocument { public: + typedef std::vector<std::string> StringList; + ServicesCustomizationDocument() {} + const std::string& initial_start_page_url() const { + return initial_start_page_url_; + } + const std::string& app_menu_section_title() const { + return app_menu_section_title_; + } + const std::string& app_menu_support_page_url() const { + return app_menu_support_page_url_; + } + const StringList& web_apps() const { return web_apps_; } + const StringList& extensions() const { return extensions_; } + protected: virtual bool ParseFromJsonValue(const DictionaryValue* root); + bool ParseStringListFromJsonValue(const ListValue* list_value, + StringList* string_list); + // Partner's welcome page that is opened right after the OOBE. - std::string initial_start_page_; + std::string initial_start_page_url_; - // Title for the partner's apps section in apps menu. - std::string app_menu_section_title_; + // Partner's featured apps URLs list. + StringList web_apps_; - // Partner's featured apps URLs. - std::list<std::string> web_apps_; + // Partner's featured extensions URLs list. + StringList extensions_; - // Partner's featured extensions URLs. - std::list<std::string> extensions_; + // Title for the partner's apps section in apps menu. + std::string app_menu_section_title_; // Partner's apps section support page URL. std::string app_menu_support_page_url_; diff --git a/chrome/browser/chromeos/customization_document_unittest.cc b/chrome/browser/chromeos/customization_document_unittest.cc index c57a0c9..620c16a 100644 --- a/chrome/browser/chromeos/customization_document_unittest.cc +++ b/chrome/browser/chromeos/customization_document_unittest.cc @@ -58,40 +58,50 @@ const char kBadStartupManifest5[] = "{" " ]" "}"; - +const char kGoodServicesManifest[] = "{" + " // Required.\n" + " \"version\": \"1.0\"," + " \"app_menu\" : {" + " \"section_title\" : \"App menu title.\"," + " \"web_apps\" : [" + " \"http://localhost/a/1\"," + " \"http://localhost/a/2\"," + " ]," + " \"support_page\": \"http://localhost/h\"," + " \"extensions\": [" + " \"http://localhost/e/1\"," + " \"http://localhost/e/2\"," + " ]," + " }," + " // Optional.\n" + " \"initial_start_page\": \"http://localhost/s\"," + "}"; } // anonymous namespace +// StartupCustomizationDocumentTest implementation. + class StartupCustomizationDocumentTest : public testing::Test { - public: + protected: chromeos::StartupCustomizationDocument customization_; }; -TEST_F(StartupCustomizationDocumentTest, LoadBadStartupManifestFromString) { - bool result = false; - result = customization_.LoadManifestFromString(kBadStartupManifest1); - EXPECT_EQ(result, false); - result = customization_.LoadManifestFromString(kBadStartupManifest2); - EXPECT_EQ(result, false); - result = customization_.LoadManifestFromString(kBadStartupManifest3); - EXPECT_EQ(result, false); - result = customization_.LoadManifestFromString(kBadStartupManifest4); - EXPECT_EQ(result, false); - result = customization_.LoadManifestFromString(kBadStartupManifest5); - EXPECT_EQ(result, false); +TEST_F(StartupCustomizationDocumentTest, LoadBadManifestFromString) { + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest1)); + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest2)); + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest3)); + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest4)); + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest5)); } -TEST_F(StartupCustomizationDocumentTest, LoadGoodStartupManifestFromString) { - bool result = false; - result = customization_.LoadManifestFromString(kGoodStartupManifest); - EXPECT_EQ(result, true); +TEST_F(StartupCustomizationDocumentTest, LoadGoodManifestFromString) { + EXPECT_TRUE(customization_.LoadManifestFromString(kGoodStartupManifest)); EXPECT_EQ(customization_.version(), "1.0"); EXPECT_EQ(customization_.product_sku(), "SKU"); EXPECT_EQ(customization_.initial_locale(), "en_US"); EXPECT_EQ(customization_.background_color(), SkColorSetRGB(0x88, 0x00, 0x88)); EXPECT_EQ(customization_.registration_url(), "http://www.google.com"); - EXPECT_EQ(customization_.GetSetupContent("en_US")->help_page_path, "setup_content/en_US/help.html"); EXPECT_EQ(customization_.GetSetupContent("en_US")->eula_page_path, @@ -101,3 +111,27 @@ TEST_F(StartupCustomizationDocumentTest, LoadGoodStartupManifestFromString) { EXPECT_EQ(customization_.GetSetupContent("ru")->eula_page_path, "setup_content/ru/eula.html"); } + +// ServicesCustomizationDocumentTest implementation. + +class ServicesCustomizationDocumentTest : public testing::Test { + protected: + chromeos::ServicesCustomizationDocument customization_; +}; + +TEST_F(ServicesCustomizationDocumentTest, LoadBadManifestFromString) { + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest1)); + EXPECT_FALSE(customization_.LoadManifestFromString(kBadStartupManifest2)); +} + +TEST_F(ServicesCustomizationDocumentTest, LoadGoodManifestFromString) { + EXPECT_TRUE(customization_.LoadManifestFromString(kGoodServicesManifest)); + EXPECT_EQ(customization_.version(), "1.0"); + EXPECT_EQ(customization_.app_menu_section_title(), "App menu title."); + EXPECT_EQ(customization_.app_menu_support_page_url(), "http://localhost/h"); + EXPECT_EQ(customization_.initial_start_page_url(), "http://localhost/s"); + EXPECT_EQ(customization_.web_apps().front(), "http://localhost/a/1"); + EXPECT_EQ(customization_.web_apps().back(), "http://localhost/a/2"); + EXPECT_EQ(customization_.extensions().front(), "http://localhost/e/1"); + EXPECT_EQ(customization_.extensions().back(), "http://localhost/e/2"); +} diff --git a/chrome/browser/chromeos/testdata/services_manifest.json b/chrome/browser/chromeos/testdata/services_manifest.json new file mode 100644 index 0000000..5efb835 --- /dev/null +++ b/chrome/browser/chromeos/testdata/services_manifest.json @@ -0,0 +1,19 @@ +{ + // Required. + "version": "1.0", + "app_menu" : { + "section_title" : "A partner application menu section title.", + "web_apps" : [ + "http://localhost/a/1", + "http://localhost/a/2", + ], + "support_page": "http://localhost/h", + "extensions": [ + "http://localhost/e/1", + "http://localhost/e/2", + ], + }, + + // Optional. + "initial_start_page": "http://localhost", +} |