9ff4de16e9228984e58a66fef9b385fc2677831b
[platform/framework/web/crosswalk.git] / src / xwalk / extensions / test / external_extension.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 "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"
14
15 using xwalk::extensions::XWalkExtensionService;
16
17 class ExternalExtensionTest : public XWalkExtensionsTestBase {
18  public:
19   virtual void SetUp() OVERRIDE {
20     XWalkExtensionService::SetExternalExtensionsPathForTesting(
21         GetExternalExtensionTestPath(FILE_PATH_LITERAL("echo_extension")));
22     XWalkExtensionsTestBase::SetUp();
23   }
24 };
25
26 class RuntimeInterfaceTest : public XWalkExtensionsTestBase {
27  public:
28   virtual void SetUp() OVERRIDE {
29     XWalkExtensionService::SetExternalExtensionsPathForTesting(
30         GetExternalExtensionTestPath(
31             FILE_PATH_LITERAL("get_runtime_variable")));
32     XWalkExtensionsTestBase::SetUp();
33   }
34 };
35
36 class MultipleEntryPointsExtension : public XWalkExtensionsTestBase {
37  public:
38   virtual void SetUp() OVERRIDE {
39     XWalkExtensionService::SetExternalExtensionsPathForTesting(
40         GetExternalExtensionTestPath(FILE_PATH_LITERAL("multiple_extension")));
41     XWalkExtensionsTestBase::SetUp();
42   }
43 };
44
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());
53 }
54
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);
61
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());
66   }
67 }
68
69 IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, ExternalExtensionSync) {
70   content::RunAllPendingInMessageLoop();
71   GURL url = GetExtensionsTestURL(
72       base::FilePath(),
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());
78 }
79
80 IN_PROC_BROWSER_TEST_F(RuntimeInterfaceTest, GetRuntimeVariable) {
81   content::RunAllPendingInMessageLoop();
82   GURL url = GetExtensionsTestURL(
83       base::FilePath(),
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());
89 }
90
91 IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, MultipleEntryPoints) {
92   content::RunAllPendingInMessageLoop();
93   GURL url = GetExtensionsTestURL(
94       base::FilePath(),
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());
100 }
101
102 IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, SetterLoadsExtension) {
103   content::RunAllPendingInMessageLoop();
104   GURL url = GetExtensionsTestURL(
105       base::FilePath(),
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());
111 }
112
113 IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, ReplacementObjectIsUsed) {
114   content::RunAllPendingInMessageLoop();
115   GURL url = GetExtensionsTestURL(
116       base::FilePath(),
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());
123 }