1 // Copyright (c) 2011 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. 4 5 #include "chrome/browser/chromeos/customization_document.h" 6 7 #include "chromeos/system/mock_statistics_provider.h" 8 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace { 12 13 const char kGoodStartupManifest[] = 14 "{" 15 " \"version\": \"1.0\"," 16 " \"initial_locale\" : \"en-US\"," 17 " \"initial_timezone\" : \"US/Pacific\"," 18 " \"keyboard_layout\" : \"xkb:us::eng\"," 19 " \"registration_url\" : \"http://www.google.com\"," 20 " \"setup_content\" : {" 21 " \"en-US\" : {" 22 " \"help_page\" : \"file:///opt/oem/help/en-US/help.html\"," 23 " \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\"," 24 " }," 25 " \"ru-RU\" : {" 26 " \"help_page\" : \"file:///opt/oem/help/ru-RU/help.html\"," 27 " \"eula_page\" : \"file:///opt/oem/eula/ru-RU/eula.html\"," 28 " }," 29 " \"default\" : {" 30 " \"help_page\" : \"file:///opt/oem/help/en/help.html\"," 31 " \"eula_page\" : \"file:///opt/oem/eula/en/eula.html\"," 32 " }," 33 " }," 34 " \"hwid_map\" : [" 35 " {" 36 " \"hwid_mask\": \"ZGA*34\"," 37 " \"initial_locale\" : \"ja\"," 38 " \"initial_timezone\" : \"Asia/Tokyo\"," 39 " \"keyboard_layout\" : \"mozc-jp\"," 40 " }," 41 " {" 42 " \"hwid_mask\": \"Mario 1?3*\"," 43 " \"initial_locale\" : \"ru-RU\"," 44 " \"initial_timezone\" : \"Europe/Moscow\"," 45 " \"keyboard_layout\" : \"xkb:ru::rus\"," 46 " }," 47 " ]," 48 "}"; 49 50 const char kBadManifest[] = "{\"version\": \"1\"}"; 51 52 const char kGoodServicesManifest[] = 53 "{" 54 " \"version\": \"1.0\"," 55 " \"app_content\" : {" 56 " \"en-US\" : {" 57 " \"initial_start_page\": \"http://mario/promo\"," 58 " \"support_page\": \"http://mario/us\"," 59 " }," 60 " \"ru-RU\" : {" 61 " \"initial_start_page\": \"http://mario/ru/promo\"," 62 " \"support_page\": \"http://mario/ru\"," 63 " }," 64 " \"default\" : {" 65 " \"initial_start_page\": \"http://mario/global/promo\"," 66 " \"support_page\": \"http://mario/global\"," 67 " }," 68 " }," 69 "}"; 70 71 } // anonymous namespace 72 73 namespace chromeos { 74 75 using ::testing::_; 76 using ::testing::DoAll; 77 using ::testing::NotNull; 78 using ::testing::Return; 79 using ::testing::SetArgumentPointee; 80 81 TEST(StartupCustomizationDocumentTest, Basic) { 82 system::MockStatisticsProvider mock_statistics_provider; 83 EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(_, NotNull())) 84 .WillRepeatedly(Return(false)); 85 EXPECT_CALL(mock_statistics_provider, 86 GetMachineStatistic(std::string("hardware_class"), NotNull())) 87 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), 88 Return(true))); 89 StartupCustomizationDocument customization(&mock_statistics_provider, 90 kGoodStartupManifest); 91 EXPECT_EQ("ru-RU", customization.initial_locale()); 92 EXPECT_EQ("Europe/Moscow", customization.initial_timezone()); 93 EXPECT_EQ("xkb:ru::rus", customization.keyboard_layout()); 94 EXPECT_EQ("http://www.google.com", customization.registration_url()); 95 96 EXPECT_EQ("file:///opt/oem/help/en-US/help.html", 97 customization.GetHelpPage("en-US")); 98 EXPECT_EQ("file:///opt/oem/help/ru-RU/help.html", 99 customization.GetHelpPage("ru-RU")); 100 EXPECT_EQ("file:///opt/oem/help/en/help.html", 101 customization.GetHelpPage("ja")); 102 103 EXPECT_EQ("file:///opt/oem/eula/en-US/eula.html", 104 customization.GetEULAPage("en-US")); 105 EXPECT_EQ("file:///opt/oem/eula/ru-RU/eula.html", 106 customization.GetEULAPage("ru-RU")); 107 EXPECT_EQ("file:///opt/oem/eula/en/eula.html", 108 customization.GetEULAPage("ja")); 109 } 110 111 TEST(StartupCustomizationDocumentTest, VPD) { 112 system::MockStatisticsProvider mock_statistics_provider; 113 EXPECT_CALL(mock_statistics_provider, 114 GetMachineStatistic(std::string("hardware_class"), NotNull())) 115 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), 116 Return(true))); 117 EXPECT_CALL(mock_statistics_provider, 118 GetMachineStatistic(std::string("initial_locale"), NotNull())) 119 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("ja")), 120 Return(true))); 121 EXPECT_CALL(mock_statistics_provider, 122 GetMachineStatistic(std::string("initial_timezone"), NotNull())) 123 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Asia/Tokyo")), 124 Return(true))); 125 EXPECT_CALL(mock_statistics_provider, 126 GetMachineStatistic(std::string("keyboard_layout"), NotNull())) 127 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("mozc-jp")), 128 Return(true))); 129 StartupCustomizationDocument customization(&mock_statistics_provider, 130 kGoodStartupManifest); 131 EXPECT_TRUE(customization.IsReady()); 132 EXPECT_EQ("ja", customization.initial_locale()); 133 EXPECT_EQ("Asia/Tokyo", customization.initial_timezone()); 134 EXPECT_EQ("mozc-jp", customization.keyboard_layout()); 135 } 136 137 TEST(StartupCustomizationDocumentTest, BadManifest) { 138 system::MockStatisticsProvider mock_statistics_provider; 139 StartupCustomizationDocument customization(&mock_statistics_provider, 140 kBadManifest); 141 EXPECT_FALSE(customization.IsReady()); 142 } 143 144 TEST(ServicesCustomizationDocumentTest, Basic) { 145 ServicesCustomizationDocument customization(kGoodServicesManifest); 146 EXPECT_TRUE(customization.IsReady()); 147 148 EXPECT_EQ("http://mario/promo", 149 customization.GetInitialStartPage("en-US")); 150 EXPECT_EQ("http://mario/ru/promo", 151 customization.GetInitialStartPage("ru-RU")); 152 EXPECT_EQ("http://mario/global/promo", 153 customization.GetInitialStartPage("ja")); 154 155 EXPECT_EQ("http://mario/us", customization.GetSupportPage("en-US")); 156 EXPECT_EQ("http://mario/ru", customization.GetSupportPage("ru-RU")); 157 EXPECT_EQ("http://mario/global", customization.GetSupportPage("ja")); 158 } 159 160 TEST(ServicesCustomizationDocumentTest, BadManifest) { 161 ServicesCustomizationDocument customization(kBadManifest); 162 EXPECT_FALSE(customization.IsReady()); 163 } 164 165 } // namespace chromeos 166