Upstream version 7.35.138.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / main_document_handler_unittest.cc
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.
4
5 #include "xwalk/application/common/manifest_handlers/main_document_handler.h"
6
7 #include "xwalk/application/common/application_manifest_constants.h"
8 #include "xwalk/application/common/constants.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace xwalk {
12
13 namespace keys = application_manifest_keys;
14
15 namespace application {
16
17 class MainDocumentHandlerTest : public testing::Test {
18  public:
19   virtual void SetUp() OVERRIDE {
20     manifest.SetString(keys::kNameKey, "no name");
21     manifest.SetString(keys::kVersionKey, "0");
22   }
23
24   scoped_refptr<ApplicationData> CreateApplication() {
25     std::string error;
26     scoped_refptr<ApplicationData> application = ApplicationData::Create(
27         base::FilePath(), Manifest::INVALID_TYPE, manifest, "", &error);
28     return application;
29   }
30
31   const MainDocumentInfo* GetMainDocInfo(const ApplicationData* application) {
32     return ToMainDocumentInfo(application->GetManifestData(keys::kAppMainKey));
33   }
34
35   base::DictionaryValue manifest;
36 };
37
38 TEST_F(MainDocumentHandlerTest, MainSource) {
39   manifest.SetString(keys::kAppMainSourceKey, "1.html");
40   scoped_refptr<ApplicationData> application = CreateApplication();
41
42   ASSERT_TRUE(application.get());
43   EXPECT_EQ(GetMainDocInfo(application)->GetMainURL(),
44             application->GetResourceURL("1.html"));
45 }
46
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();
53
54   ASSERT_TRUE(application.get());
55   EXPECT_EQ(GetMainDocInfo(application)->GetMainURL(),
56             application->GetResourceURL(kGeneratedMainDocumentFilename));
57   EXPECT_EQ(GetMainDocInfo(application)->GetMainScripts().size(), 2);
58
59   scripts->AppendInteger(1);
60   application = CreateApplication();
61   EXPECT_FALSE(application.get());
62 }
63
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();
72
73   ASSERT_TRUE(application.get());
74   EXPECT_EQ(GetMainDocInfo(application)->GetMainURL(),
75             application->GetResourceURL("1.html"));
76 }
77
78 }  // namespace application
79 }  // namespace xwalk