52c6e38633702089d01e5198dd653ef74e8d1935
[platform/framework/web/crosswalk.git] / src / xwalk / application / test / application_multi_app_test.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 "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"
14
15 using xwalk::application::Application;
16 using xwalk::application::ApplicationService;
17
18 class ApplicationMultiAppTest : public ApplicationBrowserTest {
19 };
20
21 IN_PROC_BROWSER_TEST_F(ApplicationMultiAppTest, TestMultiApp) {
22   ApplicationService* service = application_sevice();
23   // Launch the first app.
24   Application* app1 = service->Launch(
25       test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app1")));
26   ASSERT_TRUE(app1);
27   // Wait for app is fully loaded.
28   test_runner_->WaitForTestNotification();
29   EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
30   // The App1 has 2 pages: main doc page and "main.html" page.
31   EXPECT_EQ(app1->runtimes().size(), 2);
32   ASSERT_TRUE(app1->GetMainDocumentRuntime());
33
34   EXPECT_EQ(service->active_applications().size(), 1);
35   EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
36
37   // Verify that no new App instance was created, if one exists
38   // with the same ID.
39   Application* failed_app1 = service->Launch(
40       test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app1")));
41   ASSERT_FALSE(failed_app1);
42
43   // Launch the second app.
44   Application* app2 = service->Launch(
45       test_data_dir_.Append(FILE_PATH_LITERAL("dummy_app2")));
46   ASSERT_TRUE(app2);
47   // Wait for app is fully loaded.
48   test_runner_->PostResultToNotificationCallback();
49   test_runner_->WaitForTestNotification();
50   EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
51
52   // The App2 also has 2 pages: main doc page and "main.html" page.
53   EXPECT_EQ(app2->runtimes().size(), 2);
54   ASSERT_TRUE(app2->GetMainDocumentRuntime());
55
56   // Check that the apps have different IDs and RPH IDs.
57   EXPECT_NE(app1->id(), app2->id());
58   EXPECT_NE(app1->GetRenderProcessHostID(), app2->GetRenderProcessHostID());
59
60   EXPECT_EQ(service->active_applications().size(), 2);
61   EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
62   EXPECT_EQ(service->GetApplicationByID(app2->id()), app2);
63
64   app1->Terminate();
65   content::RunAllPendingInMessageLoop();
66   EXPECT_EQ(service->active_applications().size(), 1);
67
68   app2->Terminate();
69   content::RunAllPendingInMessageLoop();
70   EXPECT_EQ(service->active_applications().size(), 0);
71 }