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
|
// Copyright 2014 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 "base/strings/stringprintf.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/guest_view/guest_view_manager.h"
#include "extensions/browser/guest_view/guest_view_manager_factory.h"
#include "extensions/browser/guest_view/test_guest_view_manager.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
class AppViewTest : public extensions::PlatformAppBrowserTest {
public:
AppViewTest() {
extensions::GuestViewManager::set_factory_for_testing(&factory_);
}
enum TestServer {
NEEDS_TEST_SERVER,
NO_TEST_SERVER
};
void TestHelper(const std::string& test_name,
const std::string& app_location,
const std::string& app_to_embed,
TestServer test_server) {
// For serving guest pages.
if (test_server == NEEDS_TEST_SERVER) {
if (!StartEmbeddedTestServer()) {
LOG(ERROR) << "FAILED TO START TEST SERVER.";
return;
}
}
LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
// Flush any pending events to make sure we start with a clean slate.
content::RunAllPendingInMessageLoop();
content::WebContents* embedder_web_contents =
GetFirstAppWindowWebContents();
if (!embedder_web_contents) {
LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
return;
}
ExtensionTestMessageListener done_listener("TEST_PASSED", false);
done_listener.set_failure_message("TEST_FAILED");
if (!content::ExecuteScript(
embedder_web_contents,
base::StringPrintf("runTest('%s', '%s')",
test_name.c_str(),
app_to_embed.c_str()))) {
LOG(ERROR) << "UNABLE TO START TEST.";
return;
}
ASSERT_TRUE(done_listener.WaitUntilSatisfied());
}
private:
void SetUpCommandLine(base::CommandLine* command_line) override {
extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
}
extensions::TestGuestViewManagerFactory factory_;
};
// Tests that <appview> is able to navigate to another installed app.
IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) {
const extensions::Extension* skeleton_app =
InstallPlatformApp("app_view/shim/skeleton");
TestHelper("testAppViewWithUndefinedDataShouldSucceed",
"app_view/shim",
skeleton_app->id(),
NO_TEST_SERVER);
}
// Tests that <appview> correctly processes parameters passed on connect.
IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) {
const extensions::Extension* skeleton_app =
InstallPlatformApp("app_view/shim/skeleton");
TestHelper("testAppViewRefusedDataShouldFail",
"app_view/shim",
skeleton_app->id(),
NO_TEST_SERVER);
}
// Tests that <appview> correctly processes parameters passed on connect.
IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) {
const extensions::Extension* skeleton_app =
InstallPlatformApp("app_view/shim/skeleton");
TestHelper("testAppViewGoodDataShouldSucceed",
"app_view/shim",
skeleton_app->id(),
NO_TEST_SERVER);
}
// Tests that <appview> correctly handles multiple successive connects.
IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewMultipleConnects) {
const extensions::Extension* skeleton_app =
InstallPlatformApp("app_view/shim/skeleton");
TestHelper("testAppViewMultipleConnects",
"app_view/shim",
skeleton_app->id(),
NO_TEST_SERVER);
}
|