| Index: remoting/host/setup/me2me_native_messaging_host_unittest.cc
|
| diff --git a/remoting/host/setup/me2me_native_messaging_host_unittest.cc b/remoting/host/setup/me2me_native_messaging_host_unittest.cc
|
| index 922f9965c0ba68053b59e9a6dca10f3cead28c31..3b6f9c43a81a69039f818d1b86aada24904552f9 100644
|
| --- a/remoting/host/setup/me2me_native_messaging_host_unittest.cc
|
| +++ b/remoting/host/setup/me2me_native_messaging_host_unittest.cc
|
| @@ -162,10 +162,13 @@ class MockDaemonControllerDelegate : public DaemonController::Delegate {
|
| void SetConfigAndStart(
|
| scoped_ptr<base::DictionaryValue> config,
|
| bool consent,
|
| - const DaemonController::CompletionCallback& done) override;
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) override;
|
| void UpdateConfig(scoped_ptr<base::DictionaryValue> config,
|
| - const DaemonController::CompletionCallback& done) override;
|
| - void Stop(const DaemonController::CompletionCallback& done) override;
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) override;
|
| + void Stop(const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) override;
|
| DaemonController::UsageStatsConsent GetUsageStatsConsent() override;
|
|
|
| private:
|
| @@ -187,29 +190,32 @@ scoped_ptr<base::DictionaryValue> MockDaemonControllerDelegate::GetConfig() {
|
| void MockDaemonControllerDelegate::SetConfigAndStart(
|
| scoped_ptr<base::DictionaryValue> config,
|
| bool consent,
|
| - const DaemonController::CompletionCallback& done) {
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
|
|
| // Verify parameters passed in.
|
| if (consent && config && config->HasKey("start")) {
|
| - done.Run(DaemonController::RESULT_OK);
|
| + on_done.Run();
|
| } else {
|
| - done.Run(DaemonController::RESULT_FAILED);
|
| + on_error.Run("Missing 'start'", FROM_HERE);
|
| }
|
| }
|
|
|
| void MockDaemonControllerDelegate::UpdateConfig(
|
| scoped_ptr<base::DictionaryValue> config,
|
| - const DaemonController::CompletionCallback& done) {
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| if (config && config->HasKey("update")) {
|
| - done.Run(DaemonController::RESULT_OK);
|
| + on_done.Run();
|
| } else {
|
| - done.Run(DaemonController::RESULT_FAILED);
|
| + on_error.Run("Missing 'update'", FROM_HERE);
|
| }
|
| }
|
|
|
| void MockDaemonControllerDelegate::Stop(
|
| - const DaemonController::CompletionCallback& done) {
|
| - done.Run(DaemonController::RESULT_OK);
|
| + const base::Closure& on_done,
|
| + const DaemonController::ErrorCallback& on_error) {
|
| + on_done.Run();
|
| }
|
|
|
| DaemonController::UsageStatsConsent
|
| @@ -233,11 +239,9 @@ class Me2MeNativeMessagingHostTest : public testing::Test {
|
|
|
| void WriteMessageToInputPipe(const base::Value& message);
|
|
|
| - // The Host process should shut down when it receives a malformed request.
|
| - // This is tested by sending a known-good request, followed by |message|,
|
| - // followed by the known-good request again. The response file should only
|
| - // contain a single response from the first good request.
|
| - void TestBadRequest(const base::Value& message);
|
| + void TestBadDictionary(const base::DictionaryValue& message);
|
| + void TestBadRequest(const base::Value& message,
|
| + const std::string& expected_type);
|
|
|
| protected:
|
| // Reference to the MockDaemonControllerDelegate, which is owned by
|
| @@ -417,7 +421,16 @@ void Me2MeNativeMessagingHostTest::WriteMessageToInputPipe(
|
| input_write_file_.WriteAtCurrentPos(message_json.data(), length);
|
| }
|
|
|
| -void Me2MeNativeMessagingHostTest::TestBadRequest(const base::Value& message) {
|
| +void Me2MeNativeMessagingHostTest::TestBadDictionary(
|
| + const base::DictionaryValue& message) {
|
| + std::string type;
|
| + EXPECT_TRUE(message.GetString("type", &type));
|
| + TestBadRequest(message, type + "Response");
|
| +}
|
| +
|
| +void Me2MeNativeMessagingHostTest::TestBadRequest(
|
| + const base::Value& message,
|
| + const std::string& expected_type) {
|
| base::DictionaryValue good_message;
|
| good_message.SetString("type", "hello");
|
|
|
| @@ -425,17 +438,28 @@ void Me2MeNativeMessagingHostTest::TestBadRequest(const base::Value& message) {
|
| // message parameters verification.
|
| WriteMessageToInputPipe(good_message);
|
| WriteMessageToInputPipe(message);
|
| - WriteMessageToInputPipe(good_message);
|
|
|
| // Read from output pipe, and verify responses.
|
| scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
|
| VerifyHelloResponse(response.Pass());
|
|
|
| response = ReadMessageFromOutputPipe();
|
| - EXPECT_FALSE(response);
|
| + EXPECT_TRUE(response);
|
| +
|
| + // If a type is expected, assert that it matches (note that a type is expected
|
| + // for all message that included one).
|
| + std::string value;
|
| + if (!expected_type.empty()) {
|
| + EXPECT_TRUE(response->GetString("type", &value));
|
| + EXPECT_EQ(expected_type, value);
|
| + } else {
|
| + EXPECT_FALSE(response->GetString("type", &value));
|
| + }
|
| +
|
| + EXPECT_TRUE(response->GetString("error_message", &value));
|
| + EXPECT_TRUE(response->GetString("error_location", &value));
|
| }
|
|
|
| -// TODO (weitaosu): crbug.com/323306. Re-enable these tests.
|
| // Test all valid request-types.
|
| TEST_F(Me2MeNativeMessagingHostTest, All) {
|
| int next_id = 0;
|
| @@ -551,20 +575,20 @@ TEST_F(Me2MeNativeMessagingHostTest, Id) {
|
| // Verify non-Dictionary requests are rejected.
|
| TEST_F(Me2MeNativeMessagingHostTest, WrongFormat) {
|
| base::ListValue message;
|
| - TestBadRequest(message);
|
| + TestBadRequest(message, "");
|
| }
|
|
|
| // Verify requests with no type are rejected.
|
| TEST_F(Me2MeNativeMessagingHostTest, MissingType) {
|
| base::DictionaryValue message;
|
| - TestBadRequest(message);
|
| + TestBadRequest(message, "");
|
| }
|
|
|
| // Verify rejection if type is unrecognized.
|
| TEST_F(Me2MeNativeMessagingHostTest, InvalidType) {
|
| base::DictionaryValue message;
|
| message.SetString("type", "xxx");
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| // Verify rejection if getPinHash request has no hostId.
|
| @@ -572,7 +596,7 @@ TEST_F(Me2MeNativeMessagingHostTest, GetPinHashNoHostId) {
|
| base::DictionaryValue message;
|
| message.SetString("type", "getPinHash");
|
| message.SetString("pin", "1234");
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| // Verify rejection if getPinHash request has no pin.
|
| @@ -580,7 +604,7 @@ TEST_F(Me2MeNativeMessagingHostTest, GetPinHashNoPin) {
|
| base::DictionaryValue message;
|
| message.SetString("type", "getPinHash");
|
| message.SetString("hostId", "my_host");
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| // Verify rejection if updateDaemonConfig request has invalid config.
|
| @@ -588,7 +612,7 @@ TEST_F(Me2MeNativeMessagingHostTest, UpdateDaemonConfigInvalidConfig) {
|
| base::DictionaryValue message;
|
| message.SetString("type", "updateDaemonConfig");
|
| message.SetString("config", "xxx");
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| // Verify rejection if startDaemon request has invalid config.
|
| @@ -597,7 +621,7 @@ TEST_F(Me2MeNativeMessagingHostTest, StartDaemonInvalidConfig) {
|
| message.SetString("type", "startDaemon");
|
| message.SetString("config", "xxx");
|
| message.SetBoolean("consent", true);
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| // Verify rejection if startDaemon request has no "consent" parameter.
|
| @@ -605,14 +629,14 @@ TEST_F(Me2MeNativeMessagingHostTest, StartDaemonNoConsent) {
|
| base::DictionaryValue message;
|
| message.SetString("type", "startDaemon");
|
| message.Set("config", base::DictionaryValue().DeepCopy());
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| // Verify rejection if getCredentialsFromAuthCode has no auth code.
|
| TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) {
|
| base::DictionaryValue message;
|
| message.SetString("type", "getCredentialsFromAuthCode");
|
| - TestBadRequest(message);
|
| + TestBadDictionary(message);
|
| }
|
|
|
| } // namespace remoting
|
|
|