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(), 2);
33 ASSERT_TRUE(app1->GetMainDocumentRuntime());
35 EXPECT_EQ(service->active_applications().size(), currently_running_count + 1);
36 EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
38 // Verify that no new App instance was created, if one exists
40 Application* failed_app1 = service->Launch(
41 test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app1")));
42 ASSERT_FALSE(failed_app1);
44 // Launch the second app.
45 Application* app2 = service->Launch(
46 test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app2")));
48 // Wait for app is fully loaded.
49 test_runner_->PostResultToNotificationCallback();
50 test_runner_->WaitForTestNotification();
51 EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
53 // The App2 also has 2 pages: main doc page and "main.html" page.
54 EXPECT_EQ(app2->runtimes().size(), 2);
55 ASSERT_TRUE(app2->GetMainDocumentRuntime());
57 // Check that the apps have different IDs and RPH IDs.
58 EXPECT_NE(app1->id(), app2->id());
59 EXPECT_NE(app1->GetRenderProcessHostID(), app2->GetRenderProcessHostID());
61 EXPECT_EQ(service->active_applications().size(), currently_running_count + 2);
62 EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
63 EXPECT_EQ(service->GetApplicationByID(app2->id()), app2);
66 content::RunAllPendingInMessageLoop();
67 EXPECT_EQ(service->active_applications().size(), currently_running_count + 1);
70 content::RunAllPendingInMessageLoop();
71 EXPECT_EQ(service->active_applications().size(), currently_running_count);