Skip to content

Commit

Permalink
Add main document browser test
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlong committed Sep 17, 2013
1 parent aa5d171 commit ba38872
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 2 deletions.
4 changes: 2 additions & 2 deletions application/common/manifest_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ TEST_F(ManifestTest, ApplicationTypes) {

// Platform app.
MutateManifest(
&manifest, keys::kPlatformAppBackgroundKey, new base::DictionaryValue());
&manifest, keys::kAppMainKey, new base::DictionaryValue());
AssertType(manifest.get(), Manifest::TYPE_PACKAGED_APP);
MutateManifest(
&manifest, keys::kPlatformAppBackgroundKey, NULL);
&manifest, keys::kAppMainKey, NULL);

// Hosted app.
MutateManifest(
Expand Down
89 changes: 89 additions & 0 deletions application/test/application_main_document_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) 2013 Intel Corporation. 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/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "net/base/net_util.h"
#include "xwalk/application/browser/application_system.h"
#include "xwalk/application/common/application.h"
#include "xwalk/application/common/constants.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/runtime_registry.h"
#include "xwalk/runtime/common/xwalk_notification_types.h"
#include "xwalk/test/base/in_process_browser_test.h"

namespace {

bool WaitForRuntimeCountCallback(int* count) {
--(*count);
return *count == 0;
}

} // namespace

using xwalk::application::Application;
using xwalk::Runtime;
using xwalk::RuntimeRegistry;

class ApplicationMainDocumentBrowserTest: public InProcessBrowserTest {
public:
virtual void SetUp() OVERRIDE;
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;

base::FilePath test_data_dir_;
};

void ApplicationMainDocumentBrowserTest::SetUp() {
PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_);
test_data_dir_ = test_data_dir_
.Append(FILE_PATH_LITERAL("xwalk"))
.Append(FILE_PATH_LITERAL("application"))
.Append(FILE_PATH_LITERAL("test"))
.Append(FILE_PATH_LITERAL("data"));
InProcessBrowserTest::SetUp();
}

void ApplicationMainDocumentBrowserTest::SetUpCommandLine(
CommandLine* command_line) {
GURL url = net::FilePathToFileURL(test_data_dir_.Append(
FILE_PATH_LITERAL("main_document")));
command_line->AppendArg(url.spec());
}

// Verifies the runtime creation when main document is used.
IN_PROC_BROWSER_TEST_F(ApplicationMainDocumentBrowserTest, MainDocument) {
content::RunAllPendingInMessageLoop();
const xwalk::RuntimeList& runtimes = RuntimeRegistry::Get()->runtimes();
// At least the main document's runtime exist after launch.
ASSERT_GE(runtimes.size(), 1);

Runtime* main_runtime = runtimes[0];
xwalk::RuntimeContext* runtime_context = main_runtime->runtime_context();
xwalk::application::ApplicationService* service =
runtime_context->GetApplicationSystem()->application_service();
const Application* app = service->GetRunningApplication();
GURL generated_url =
app->GetResourceURL(xwalk::application::kGeneratedMainDocumentFilename);
// Check main document URL.
ASSERT_EQ(main_runtime->web_contents()->GetURL(), generated_url);
ASSERT_TRUE(!main_runtime->window());

// There should exist 2 runtimes(one for generated main document, one for the
// window created by main document). As WindowedNotificationObserver::Wait()
// will call the callback function once when inovke, so add one more for the
// Wait() to consume.
int count = 2 - runtimes.size() + 1;
if (count > 1) {
content::WindowedNotificationObserver(
xwalk::NOTIFICATION_RUNTIME_OPENED,
base::Bind(&WaitForRuntimeCountCallback, &count)).Wait();
}

ASSERT_EQ(2, RuntimeRegistry::Get()->runtimes().size());
}
5 changes: 5 additions & 0 deletions application/test/data/main_document/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1> hello </h1>
</body>
</html>
4 changes: 4 additions & 0 deletions application/test/data/main_document/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
setTimeout(
function(){
window.open("main.html");
}, 100);
10 changes: 10 additions & 0 deletions application/test/data/main_document/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "main_document_test",
"manifest_version": 1,
"version": "1.0",
"app": {
"main": {
"scripts": ["main.js"]
}
}
}
1 change: 1 addition & 0 deletions xwalk_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'sources': [
'application/test/application_main_document_browsertest.cc',
'runtime/browser/xwalk_download_browsertest.cc',
'runtime/browser/xwalk_form_input_browsertest.cc',
'runtime/browser/xwalk_runtime_browsertest.cc',
Expand Down

0 comments on commit ba38872

Please sign in to comment.