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 "content/public/test/browser_test_utils.h"
6 #include "content/public/test/test_utils.h"
7 #include "net/base/net_util.h"
8 #include "xwalk/application/browser/application.h"
9 #include "xwalk/application/browser/application_service.h"
10 #include "xwalk/application/browser/application_system.h"
11 #include "xwalk/application/test/application_browsertest.h"
12 #include "xwalk/application/test/application_testapi.h"
13 #include "xwalk/runtime/browser/xwalk_runner.h"
15 using xwalk::application::Application;
16 using xwalk::application::ApplicationService;
18 class ApplicationMultiAppTest : public ApplicationBrowserTest {
21 IN_PROC_BROWSER_TEST_F(ApplicationMultiAppTest, TestMultiApp) {
22 ApplicationService* service = application_sevice();
23 const size_t currently_running_count = service->active_applications().size();
24 // Launch the first app.
25 Application* app1 = service->Launch(
26 test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app1")));
28 // Wait for app is fully loaded.
29 test_runner_->WaitForTestNotification();
30 EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
31 // The App1 has 2 pages: main doc page and "main.html" page.
32 EXPECT_EQ(app1->runtimes().size(), 1);
34 EXPECT_EQ(service->active_applications().size(), currently_running_count + 1);
35 EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
37 // Verify that no new App instance was created, if one exists
39 Application* failed_app1 = service->Launch(
40 test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app1")));
41 ASSERT_FALSE(failed_app1);
43 // Launch the second app.
44 Application* app2 = service->Launch(
45 test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app2")));
47 // Wait for app is fully loaded.
48 test_runner_->PostResultToNotificationCallback();
49 test_runner_->WaitForTestNotification();
50 EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
52 // The App2 also has 2 pages: main doc page and "main.html" page.
53 EXPECT_EQ(app2->runtimes().size(), 1);
55 // Check that the apps have different IDs and RPH IDs.
56 EXPECT_NE(app1->id(), app2->id());
57 EXPECT_NE(app1->GetRenderProcessHostID(), app2->GetRenderProcessHostID());
59 EXPECT_EQ(service->active_applications().size(), currently_running_count + 2);
60 EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
61 EXPECT_EQ(service->GetApplicationByID(app2->id()), app2);
64 content::RunAllPendingInMessageLoop();
65 EXPECT_EQ(service->active_applications().size(), currently_running_count + 1);
68 content::RunAllPendingInMessageLoop();
69 EXPECT_EQ(service->active_applications().size(), currently_running_count);