summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/customization_document_unittest.cc
blob: a19e63ac158ac30f16d7e7f5d3355efc9682fb18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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.

#include "chrome/browser/chromeos/customization_document.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace {

const char kGoodStartupManifest[] =
    "{"
    "  \"version\": \"1.0\","
    "  \"product_sku\" : \"SKU\","
    "  \"initial_locale\" : \"en_US\","
    "  \"initial_timezone\" : \"US/Pacific\","
    "  \"background_color\" : \"#880088\","
    "  \"registration_url\" : \"http://www.google.com\","
    "  \"setup_content\" : ["
    "    {"
    "      \"content_locale\" : \"en_US\","
    "      \"help_page\" : \"setup_content/en_US/help.html\","
    "      \"eula_page\" : \"setup_content/en_US/eula.html\","
    "    },"
    "    {"
    "      \"content_locale\" : \"ru\","
    "      \"help_page\" : \"setup_content/ru/help.html\","
    "      \"eula_page\" : \"setup_content/ru/eula.html\","
    "    },"
    "  ]"
    "}";

const char kBadStartupManifest1[] = "{}";
const char kBadStartupManifest2[] = "{ \"version\" : \"1.0\" }";
const char kBadStartupManifest3[] = "{"
    "  \"version\" : \"0.0\","
    "  \"product_sku\" : \"SKU\","
    "}";

const char kBadStartupManifest4[] = "{"
    "  \"version\" : \"1.0\","
    "  \"product_sku\" : \"SKU\","
    "  \"setup_content\" : ["
    "    {"
    "      \"help_page\" : \"setup_content/en_US/help.html\","
    "      \"eula_page\" : \"setup_content/en_US/eula.html\","
    "    },"
    "  ]"
    "}";

const char kBadStartupManifest5[] = "{"
    "  \"version\" : \"1.0\","
    "  \"product_sku\" : \"SKU\","
    "  \"setup_content\" : ["
    "    {"
    "      \"content_locale\" : \"en_US\","
    "      \"eula_page\" : \"setup_content/en_US/eula.html\","
    "    },"
    "  ]"
    "}";

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 {
 protected:
  chromeos::StartupCustomizationDocument customization_;
};

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, 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_.initial_timezone(), "US/Pacific");
  EXPECT_EQ(customization_.background_color(),
            SkColorSetRGB(0x88, 0x00, 0x88));
  EXPECT_EQ(customization_.registration_url(), "http://www.google.com");
  EXPECT_EQ(customization_.GetHelpPagePath("en_US").value(),
            "setup_content/en_US/help.html");
  EXPECT_EQ(customization_.GetEULAPagePath("en_US").value(),
            "setup_content/en_US/eula.html");
  EXPECT_EQ(customization_.GetHelpPagePath("ru").value(),
            "setup_content/ru/help.html");
  EXPECT_EQ(customization_.GetEULAPagePath("ru").value(),
            "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");
}