Commit 15161ce4 authored by hirono's avatar hirono Committed by Commit bot

Files.app: Refactoring for the onMessage function of FileManagerBrowserTest.

Previously onMessage function of FileManagerBrowserTest returns a string, but
the format of the return values is not consistent among the message types.

Also the onMessage function retunrs the value even if it is fatal error, but for
the case, we can stop the test directly in the function.

The CL removes unrequired result values, and adds test assertions for fatal
errors.

BUG=None
TEST=None

Review URL: https://codereview.chromium.org/667843005

Cr-Commit-Position: refs/heads/master@{#301076}
parent 8e60ab5d
...@@ -545,8 +545,9 @@ class FileManagerBrowserTestBase : public ExtensionApiTest { ...@@ -545,8 +545,9 @@ class FileManagerBrowserTestBase : public ExtensionApiTest {
} }
virtual GuestMode GetGuestModeParam() const = 0; virtual GuestMode GetGuestModeParam() const = 0;
virtual const char* GetTestCaseNameParam() const = 0; virtual const char* GetTestCaseNameParam() const = 0;
virtual std::string OnMessage(const std::string& name, virtual void OnMessage(const std::string& name,
const base::Value* value); const base::Value& value,
std::string* output);
scoped_ptr<LocalTestVolume> local_volume_; scoped_ptr<LocalTestVolume> local_volume_;
linked_ptr<DriveTestVolume> drive_volume_; linked_ptr<DriveTestVolume> drive_volume_;
...@@ -642,16 +643,24 @@ void FileManagerBrowserTestBase::RunTestMessageLoop() { ...@@ -642,16 +643,24 @@ void FileManagerBrowserTestBase::RunTestMessageLoop() {
!message_dictionary->GetString("name", &name)) !message_dictionary->GetString("name", &name))
continue; continue;
entry.function->Reply(OnMessage(name, value.get())); std::string output;
OnMessage(name, *value.get(), &output);
if (HasFatalFailure())
break;
entry.function->Reply(output);
} }
} }
std::string FileManagerBrowserTestBase::OnMessage(const std::string& name, void FileManagerBrowserTestBase::OnMessage(const std::string& name,
const base::Value* value) { const base::Value& value,
std::string* output) {
if (name == "getTestName") { if (name == "getTestName") {
// Pass the test case name. // Pass the test case name.
return GetTestCaseNameParam(); *output = GetTestCaseNameParam();
} else if (name == "getRootPaths") { return;
}
if (name == "getRootPaths") {
// Pass the root paths. // Pass the root paths.
const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
res->SetString("downloads", res->SetString("downloads",
...@@ -659,13 +668,17 @@ std::string FileManagerBrowserTestBase::OnMessage(const std::string& name, ...@@ -659,13 +668,17 @@ std::string FileManagerBrowserTestBase::OnMessage(const std::string& name,
res->SetString("drive", res->SetString("drive",
"/" + drive::util::GetDriveMountPointPath(profile() "/" + drive::util::GetDriveMountPointPath(profile()
).BaseName().AsUTF8Unsafe() + "/root"); ).BaseName().AsUTF8Unsafe() + "/root");
std::string jsonString; base::JSONWriter::Write(res.get(), output);
base::JSONWriter::Write(res.get(), &jsonString); return;
return jsonString; }
} else if (name == "isInGuestMode") {
if (name == "isInGuestMode") {
// Obtain whether the test is in guest mode or not. // Obtain whether the test is in guest mode or not.
return GetGuestModeParam() != NOT_IN_GUEST_MODE ? "true" : "false"; *output = GetGuestModeParam() != NOT_IN_GUEST_MODE ? "true" : "false";
} else if (name == "getCwsWidgetContainerMockUrl") { return;
}
if (name == "getCwsWidgetContainerMockUrl") {
// Obtain whether the test is in guest mode or not. // Obtain whether the test is in guest mode or not.
const GURL url = embedded_test_server()->GetURL( const GURL url = embedded_test_server()->GetURL(
"/chromeos/file_manager/cws_container_mock/index.html"); "/chromeos/file_manager/cws_container_mock/index.html");
...@@ -678,15 +691,16 @@ std::string FileManagerBrowserTestBase::OnMessage(const std::string& name, ...@@ -678,15 +691,16 @@ std::string FileManagerBrowserTestBase::OnMessage(const std::string& name,
const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
res->SetString("url", url.spec()); res->SetString("url", url.spec());
res->SetString("origin", origin); res->SetString("origin", origin);
std::string jsonString; base::JSONWriter::Write(res.get(), output);
base::JSONWriter::Write(res.get(), &jsonString); return;
return jsonString; }
} else if (name == "addEntries") {
if (name == "addEntries") {
// Add entries to the specified volume. // Add entries to the specified volume.
base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter; base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter;
AddEntriesMessage message; AddEntriesMessage message;
if (!add_entries_message_converter.Convert(*value, &message)) ASSERT_TRUE(add_entries_message_converter.Convert(value, &message));
return "onError";
for (size_t i = 0; i < message.entries.size(); ++i) { for (size_t i = 0; i < message.entries.size(); ++i) {
switch (message.volume) { switch (message.volume) {
case LOCAL_VOLUME: case LOCAL_VOLUME:
...@@ -705,23 +719,29 @@ std::string FileManagerBrowserTestBase::OnMessage(const std::string& name, ...@@ -705,23 +719,29 @@ std::string FileManagerBrowserTestBase::OnMessage(const std::string& name,
break; break;
} }
} }
return "onEntryAdded";
} else if (name == "mountFakeUsb") { return;
}
if (name == "mountFakeUsb") {
usb_volume_.reset(new FakeTestVolume("fake-usb", usb_volume_.reset(new FakeTestVolume("fake-usb",
VOLUME_TYPE_REMOVABLE_DISK_PARTITION, VOLUME_TYPE_REMOVABLE_DISK_PARTITION,
chromeos::DEVICE_TYPE_USB)); chromeos::DEVICE_TYPE_USB));
usb_volume_->Mount(profile()); usb_volume_->Mount(profile());
return "true"; return;
} else if (name == "mountFakeMtp") { }
if (name == "mountFakeMtp") {
mtp_volume_.reset(new FakeTestVolume("fake-mtp", mtp_volume_.reset(new FakeTestVolume("fake-mtp",
VOLUME_TYPE_MTP, VOLUME_TYPE_MTP,
chromeos::DEVICE_TYPE_UNKNOWN)); chromeos::DEVICE_TYPE_UNKNOWN));
if (!mtp_volume_->PrepareTestEntries(profile())) ASSERT_TRUE(mtp_volume_->PrepareTestEntries(profile()));
return "false";
mtp_volume_->Mount(profile()); mtp_volume_->Mount(profile());
return "true"; return;
} }
return "unknownMessage";
FAIL() << "Unknown test message: " << name;
} }
drive::DriveIntegrationService* drive::DriveIntegrationService*
...@@ -1145,29 +1165,6 @@ class MultiProfileFileManagerBrowserTest : public FileManagerBrowserTestBase { ...@@ -1145,29 +1165,6 @@ class MultiProfileFileManagerBrowserTest : public FileManagerBrowserTestBase {
return test_case_name_.c_str(); return test_case_name_.c_str();
} }
virtual std::string OnMessage(const std::string& name,
const base::Value* value) override {
if (name == "addAllUsers") {
AddAllUsers();
return "true";
} else if (name == "getWindowOwnerId") {
chrome::MultiUserWindowManager* const window_manager =
chrome::MultiUserWindowManager::GetInstance();
extensions::AppWindowRegistry* const app_window_registry =
extensions::AppWindowRegistry::Get(profile());
DCHECK(window_manager);
DCHECK(app_window_registry);
const extensions::AppWindowRegistry::AppWindowList& list =
app_window_registry->GetAppWindowsForApp(
file_manager::kFileManagerAppId);
return list.size() == 1u ?
window_manager->GetUserPresentingWindow(
list.front()->GetNativeWindow()) : "";
}
return FileManagerBrowserTestBase::OnMessage(name, value);
}
std::string test_case_name_; std::string test_case_name_;
}; };
...@@ -1229,8 +1226,9 @@ class GalleryBrowserTestBase : public FileManagerBrowserTestBase { ...@@ -1229,8 +1226,9 @@ class GalleryBrowserTestBase : public FileManagerBrowserTestBase {
FileManagerBrowserTestBase::SetUp(); FileManagerBrowserTestBase::SetUp();
} }
virtual std::string OnMessage(const std::string& name, virtual void OnMessage(const std::string& name,
const base::Value* value) override; const base::Value& value,
std::string* output) override;
virtual const char* GetTestManifestName() const override { virtual const char* GetTestManifestName() const override {
return "gallery_test_manifest.json"; return "gallery_test_manifest.json";
...@@ -1250,15 +1248,17 @@ class GalleryBrowserTestBase : public FileManagerBrowserTestBase { ...@@ -1250,15 +1248,17 @@ class GalleryBrowserTestBase : public FileManagerBrowserTestBase {
std::string test_case_name_; std::string test_case_name_;
}; };
template<GuestMode M> template <GuestMode M>
std::string GalleryBrowserTestBase<M>::OnMessage(const std::string& name, void GalleryBrowserTestBase<M>::OnMessage(const std::string& name,
const base::Value* value) { const base::Value& value,
std::string* output) {
if (name == "getScripts") { if (name == "getScripts") {
std::string jsonString; std::string jsonString;
base::JSONWriter::Write(&scripts_, &jsonString); base::JSONWriter::Write(&scripts_, output);
return jsonString; return;
} }
return FileManagerBrowserTestBase::OnMessage(name, value);
FileManagerBrowserTestBase::OnMessage(name, value, output);
} }
typedef GalleryBrowserTestBase<NOT_IN_GUEST_MODE> GalleryBrowserTest; typedef GalleryBrowserTestBase<NOT_IN_GUEST_MODE> GalleryBrowserTest;
...@@ -1437,8 +1437,9 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase { ...@@ -1437,8 +1437,9 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase {
FileManagerBrowserTestBase::SetUpCommandLine(command_line); FileManagerBrowserTestBase::SetUpCommandLine(command_line);
} }
virtual std::string OnMessage(const std::string& name, virtual void OnMessage(const std::string& name,
const base::Value* value) override; const base::Value& value,
std::string* output) override;
virtual const char* GetTestManifestName() const override { virtual const char* GetTestManifestName() const override {
return "video_player_test_manifest.json"; return "video_player_test_manifest.json";
...@@ -1458,15 +1459,17 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase { ...@@ -1458,15 +1459,17 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase {
std::string test_case_name_; std::string test_case_name_;
}; };
template<GuestMode M> template <GuestMode M>
std::string VideoPlayerBrowserTestBase<M>::OnMessage(const std::string& name, void VideoPlayerBrowserTestBase<M>::OnMessage(const std::string& name,
const base::Value* value) { const base::Value& value,
std::string* output) {
if (name == "getScripts") { if (name == "getScripts") {
std::string jsonString; std::string jsonString;
base::JSONWriter::Write(&scripts_, &jsonString); base::JSONWriter::Write(&scripts_, output);
return jsonString; return;
} }
return FileManagerBrowserTestBase::OnMessage(name, value);
FileManagerBrowserTestBase::OnMessage(name, value, output);
} }
typedef VideoPlayerBrowserTestBase<NOT_IN_GUEST_MODE> VideoPlayerBrowserTest; typedef VideoPlayerBrowserTestBase<NOT_IN_GUEST_MODE> VideoPlayerBrowserTest;
......
...@@ -221,7 +221,6 @@ testcase.copyBetweenWindowsUsbToDrive = function() { ...@@ -221,7 +221,6 @@ testcase.copyBetweenWindowsUsbToDrive = function() {
}, },
// Add a file to USB. // Add a file to USB.
function(result) { function(result) {
chrome.test.assertTrue(JSON.parse(result));
addEntries(['usb'], [ENTRIES.hello], this.next); addEntries(['usb'], [ENTRIES.hello], this.next);
}, },
// Wait for the mount. // Wait for the mount.
...@@ -259,7 +258,6 @@ testcase.copyBetweenWindowsUsbToLocal = function() { ...@@ -259,7 +258,6 @@ testcase.copyBetweenWindowsUsbToLocal = function() {
}, },
// Add a file to USB. // Add a file to USB.
function(result) { function(result) {
chrome.test.assertTrue(JSON.parse(result));
addEntries(['usb'], [ENTRIES.hello], this.next); addEntries(['usb'], [ENTRIES.hello], this.next);
}, },
// Wait for the mount. // Wait for the mount.
...@@ -282,4 +280,3 @@ testcase.copyBetweenWindowsUsbToLocal = function() { ...@@ -282,4 +280,3 @@ testcase.copyBetweenWindowsUsbToLocal = function() {
} }
]); ]);
}; };
...@@ -69,7 +69,6 @@ testcase.fileDisplayMtp = function() { ...@@ -69,7 +69,6 @@ testcase.fileDisplayMtp = function() {
}, },
// Wait for the mount. // Wait for the mount.
function(result) { function(result) {
chrome.test.assertTrue(JSON.parse(result));
remoteCall.waitForElement(appId, MTP_VOLUME_QUERY).then(this.next); remoteCall.waitForElement(appId, MTP_VOLUME_QUERY).then(this.next);
}, },
// Click the MTP volume. // Click the MTP volume.
......
...@@ -109,9 +109,6 @@ function addEntries(volumeNames, entries, opt_callback) { ...@@ -109,9 +109,6 @@ function addEntries(volumeNames, entries, opt_callback) {
name: 'addEntries', name: 'addEntries',
volume: volume, volume: volume,
entries: entries entries: entries
}).then(function(result) {
if (result !== "onEntryAdded")
return Promise.reject('Failed to add entries to ' + volume + '.');
}); });
}); });
var resultPromise = Promise.all(volumeResultPromises); var resultPromise = Promise.all(volumeResultPromises);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment