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 "base/native_library.h"
6 #include "base/path_service.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "xwalk/extensions/browser/xwalk_extension_service.h"
9 #include "xwalk/extensions/test/xwalk_extensions_test_base.h"
10 #include "xwalk/runtime/browser/runtime.h"
11 #include "xwalk/test/base/xwalk_test_utils.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/test_utils.h"
15 using xwalk::extensions::XWalkExtensionService;
17 class ExternalExtensionTest : public XWalkExtensionsTestBase {
19 virtual void SetUp() OVERRIDE {
20 XWalkExtensionService::SetExternalExtensionsPathForTesting(
21 GetExternalExtensionTestPath(FILE_PATH_LITERAL("echo_extension")));
22 XWalkExtensionsTestBase::SetUp();
26 class RuntimeInterfaceTest : public XWalkExtensionsTestBase {
28 virtual void SetUp() OVERRIDE {
29 XWalkExtensionService::SetExternalExtensionsPathForTesting(
30 GetExternalExtensionTestPath(
31 FILE_PATH_LITERAL("get_runtime_variable")));
32 XWalkExtensionsTestBase::SetUp();
36 class MultipleEntryPointsExtension : public XWalkExtensionsTestBase {
38 virtual void SetUp() OVERRIDE {
39 XWalkExtensionService::SetExternalExtensionsPathForTesting(
40 GetExternalExtensionTestPath(FILE_PATH_LITERAL("multiple_extension")));
41 XWalkExtensionsTestBase::SetUp();
45 IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, ExternalExtension) {
46 content::RunAllPendingInMessageLoop();
47 GURL url = GetExtensionsTestURL(base::FilePath(),
48 base::FilePath().AppendASCII("echo.html"));
49 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
50 title_watcher.AlsoWaitForTitle(kFailString);
51 xwalk_test_utils::NavigateToURL(runtime(), url);
52 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());
55 IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, NavigateWithExternalExtension) {
56 content::RunAllPendingInMessageLoop();
57 GURL url = GetExtensionsTestURL(base::FilePath(),
58 base::FilePath().AppendASCII("echo.html"));
59 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
60 title_watcher.AlsoWaitForTitle(kFailString);
62 for (int i = 0; i < 5; i++) {
63 xwalk_test_utils::NavigateToURL(runtime(), url);
64 WaitForLoadStop(runtime()->web_contents());
65 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());
69 IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, ExternalExtensionSync) {
70 content::RunAllPendingInMessageLoop();
71 GURL url = GetExtensionsTestURL(
73 base::FilePath().AppendASCII("sync_echo.html"));
74 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
75 title_watcher.AlsoWaitForTitle(kFailString);
76 xwalk_test_utils::NavigateToURL(runtime(), url);
77 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());
80 IN_PROC_BROWSER_TEST_F(RuntimeInterfaceTest, GetRuntimeVariable) {
81 content::RunAllPendingInMessageLoop();
82 GURL url = GetExtensionsTestURL(
84 base::FilePath().AppendASCII("get_runtime_variable.html"));
85 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
86 title_watcher.AlsoWaitForTitle(kFailString);
87 xwalk_test_utils::NavigateToURL(runtime(), url);
88 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());
91 IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, MultipleEntryPoints) {
92 content::RunAllPendingInMessageLoop();
93 GURL url = GetExtensionsTestURL(
95 base::FilePath().AppendASCII("entry_points.html"));
96 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
97 title_watcher.AlsoWaitForTitle(kFailString);
98 xwalk_test_utils::NavigateToURL(runtime(), url);
99 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());
102 IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, SetterLoadsExtension) {
103 content::RunAllPendingInMessageLoop();
104 GURL url = GetExtensionsTestURL(
106 base::FilePath().AppendASCII("setter_callback_entry_point.html"));
107 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
108 title_watcher.AlsoWaitForTitle(kFailString);
109 xwalk_test_utils::NavigateToURL(runtime(), url);
110 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());
113 IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, ReplacementObjectIsUsed) {
114 content::RunAllPendingInMessageLoop();
115 GURL url = GetExtensionsTestURL(
117 base::FilePath().AppendASCII(
118 "lazy_loaded_extension_overrides_object.html"));
119 content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString);
120 title_watcher.AlsoWaitForTitle(kFailString);
121 xwalk_test_utils::NavigateToURL(runtime(), url);
122 EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle());