1 // Copyright (c) 2013 Intel Corporation. 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.
5 #include "xwalk/application/common/manifest_handlers/main_document_handler.h"
7 #include "xwalk/application/common/application_manifest_constants.h"
8 #include "xwalk/application/common/constants.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 namespace keys = application_manifest_keys;
15 namespace application {
17 class MainDocumentHandlerTest : public testing::Test {
19 virtual void SetUp() OVERRIDE {
20 manifest.SetString(keys::kNameKey, "no name");
21 manifest.SetString(keys::kVersionKey, "0");
24 scoped_refptr<ApplicationData> CreateApplication() {
26 scoped_refptr<ApplicationData> application = ApplicationData::Create(
27 base::FilePath(), Manifest::INVALID_TYPE, manifest, "", &error);
31 const MainDocumentInfo* GetMainDocInfo(const ApplicationData* application) {
32 return ToMainDocumentInfo(application->GetManifestData(keys::kAppMainKey));
35 base::DictionaryValue manifest;
38 TEST_F(MainDocumentHandlerTest, MainSource) {
39 manifest.SetString(keys::kAppMainSourceKey, "1.html");
40 scoped_refptr<ApplicationData> application = CreateApplication();
42 ASSERT_TRUE(application.get());
43 EXPECT_EQ(GetMainDocInfo(application)->GetMainURL(),
44 application->GetResourceURL("1.html"));
47 TEST_F(MainDocumentHandlerTest, MainScripts) {
48 base::ListValue* scripts = new base::ListValue;
49 scripts->AppendString("1.js");
50 scripts->AppendString("2.js");
51 manifest.Set(keys::kAppMainScriptsKey, scripts);
52 scoped_refptr<ApplicationData> application = CreateApplication();
54 ASSERT_TRUE(application.get());
55 EXPECT_EQ(GetMainDocInfo(application)->GetMainURL(),
56 application->GetResourceURL(kGeneratedMainDocumentFilename));
57 EXPECT_EQ(GetMainDocInfo(application)->GetMainScripts().size(), 2);
59 scripts->AppendInteger(1);
60 application = CreateApplication();
61 EXPECT_FALSE(application.get());
64 // When both main.source and main.scripts are defined in manifest, the source
65 // will be used with higher preference.
66 TEST_F(MainDocumentHandlerTest, SourceAndScripts) {
67 manifest.SetString(keys::kAppMainSourceKey, "1.html");
68 base::ListValue* scripts = new base::ListValue;
69 scripts->AppendString("1.js");
70 manifest.Set(keys::kAppMainScriptsKey, scripts);
71 scoped_refptr<ApplicationData> application = CreateApplication();
73 ASSERT_TRUE(application.get());
74 EXPECT_EQ(GetMainDocInfo(application)->GetMainURL(),
75 application->GetResourceURL("1.html"));
78 } // namespace application