Commit 7bf382c2 authored by mfoltz's avatar mfoltz Committed by Commit bot

Don't set lastError if chrome.dial.discoverNow() can't start; we always...

Don't set lastError if chrome.dial.discoverNow() can't start; we always attempt discovery and success/failure is indicated through the callback.

Add browser test for chrome.dial.discoverNow() success.

BUG=376588

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

Cr-Commit-Position: refs/heads/master@{#292584}
parent 12e564f8
...@@ -19,8 +19,6 @@ using content::BrowserThread; ...@@ -19,8 +19,6 @@ using content::BrowserThread;
namespace { namespace {
const char kDialServiceError[] = "Dial service error.";
// How often to poll for devices. // How often to poll for devices.
const int kDialRefreshIntervalSecs = 120; const int kDialRefreshIntervalSecs = 120;
...@@ -163,9 +161,6 @@ void DialDiscoverNowFunction::Work() { ...@@ -163,9 +161,6 @@ void DialDiscoverNowFunction::Work() {
bool DialDiscoverNowFunction::Respond() { bool DialDiscoverNowFunction::Respond() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!result_)
error_ = kDialServiceError;
SetResult(new base::FundamentalValue(result_)); SetResult(new base::FundamentalValue(result_));
return true; return true;
} }
......
...@@ -52,7 +52,6 @@ IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) { ...@@ -52,7 +52,6 @@ IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) {
ASSERT_TRUE(api.get()); ASSERT_TRUE(api.get());
extensions::DialRegistry::DeviceList devices; extensions::DialRegistry::DeviceList devices;
ResultCatcher catcher; ResultCatcher catcher;
DialDeviceData device1; DialDeviceData device1;
...@@ -82,12 +81,17 @@ IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) { ...@@ -82,12 +81,17 @@ IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) {
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
} }
// Test discoverNow fails if there are no listeners. When there are no listeners
// the DIAL API will not be active.
IN_PROC_BROWSER_TEST_F(DialAPITest, Discovery) { IN_PROC_BROWSER_TEST_F(DialAPITest, Discovery) {
ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "discovery.html")); ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "discovery.html"));
} }
// discoverNow does not do discovery when there are no listeners; in that case
// the DIAL service will not be active.
IN_PROC_BROWSER_TEST_F(DialAPITest, DiscoveryNoListeners) {
ASSERT_TRUE(RunExtensionSubtest("dial/experimental",
"discovery_no_listeners.html"));
}
// Make sure this API is only accessible to whitelisted extensions. // Make sure this API is only accessible to whitelisted extensions.
IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) { IN_PROC_BROWSER_TEST_F(DialAPITest, NonWhitelistedExtension) {
ResultCatcher catcher; ResultCatcher catcher;
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
onload = function() { onload = function() {
chrome.test.runTests([ chrome.test.runTests([
function discovery() { function discoverySucceeds() {
var discoverNowShouldFail = function(result) { var discoverNowCallback = function(result) {
if (!result) { chrome.test.assertNoLastError();
chrome.test.succeed(); // The result may be true or false depending on whether periodic
} else { // discovery is running at the same time.
chrome.test.fail(); // TODO(mfoltz): We may want to update the API to distinguish error cases
} // from simultaneous discovery.
chrome.test.assertTrue(typeof(result) == 'boolean');
chrome.test.succeed();
}; };
chrome.dial.discoverNow(discoverNowShouldFail); chrome.dial.onDeviceList.addListener(function(deviceList) {});
chrome.dial.discoverNow(discoverNowCallback);
} }
]); ]);
}; };
\ No newline at end of file
<script src="discovery_no_listeners.js"></script>
\ No newline at end of file
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onload = function() {
chrome.test.runTests([
function discoverNowWithoutListeners() {
var discoverNowCallback = function(result) {
chrome.test.assertNoLastError();
chrome.test.assertTrue(typeof(result) == 'boolean');
if (!result) {
chrome.test.succeed();
} else {
chrome.test.fail();
}
};
chrome.dial.discoverNow(discoverNowCallback);
}
]);
};
\ No newline at end of file
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