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/file_util.h"
6 #include "base/path_service.h"
7 #include "content/public/test/browser_test_utils.h"
8 #include "content/public/test/test_utils.h"
9 #include "net/base/net_util.h"
11 #include "xwalk/application/test/application_browsertest.h"
12 #include "xwalk/application/test/application_testapi.h"
13 #include "xwalk/runtime/browser/runtime.h"
14 #include "xwalk/runtime/browser/runtime_context.h"
15 #include "xwalk/runtime/common/xwalk_paths.h"
16 #include "xwalk/runtime/common/xwalk_switches.h"
18 using xwalk::application::Application;
20 class ApplicationEventTest : public ApplicationBrowserTest {
22 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
23 ApplicationBrowserTest::SetUpCommandLine(command_line);
24 GURL url = net::FilePathToFileURL(test_data_dir_.Append(
25 FILE_PATH_LITERAL("event")));
26 command_line->AppendArg(url.spec());
30 class ApplicationOnInstalledEventTest : public ApplicationBrowserTest {
32 ApplicationOnInstalledEventTest() {
33 PathService::Get(xwalk::DIR_TEST_DATA, &app_data_path_);
34 app_data_path_ = app_data_path_
35 .Append(FILE_PATH_LITERAL("appdata_storage"));
38 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
39 DeleteApplicationDataPath();
41 ApplicationBrowserTest::SetUpCommandLine(command_line);
42 command_line->AppendSwitchPath(switches::kXWalkDataPath, app_data_path_);
43 command_line->AppendSwitch(switches::kInstall);
45 GURL url = net::FilePathToFileURL(test_data_dir_.Append(
46 FILE_PATH_LITERAL("event")));
47 command_line->AppendArg(url.spec());
50 bool DeleteApplicationDataPath() {
51 base::FilePath resources(app_data_path_);
52 if (base::DirectoryExists(resources) &&
53 !base::DeleteFile(resources, true))
59 base::FilePath app_data_path_;
62 IN_PROC_BROWSER_TEST_F(ApplicationEventTest, OnLaunchAndSuspendEventTest) {
63 // Wait for 'OnLaunch' event notification.
64 test_runner_->WaitForTestNotification();
65 EXPECT_EQ(ApiTestRunner::PASS, test_runner_->GetTestsResult());
67 EXPECT_EQ(application_sevice()->active_applications().size(), 1);
69 application_sevice()->active_applications()[0];
70 test_runner_->PostResultToNotificationCallback();
72 // Wait for 'OnSuspend' event notification.
73 test_runner_->WaitForTestNotification();
74 EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
77 IN_PROC_BROWSER_TEST_F(ApplicationOnInstalledEventTest, OnInstalledEventTest) {
78 test_runner_->WaitForTestNotification();
79 EXPECT_EQ(ApiTestRunner::PASS, test_runner_->GetTestsResult());
81 DeleteApplicationDataPath();