| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/local_discovery/privetv3_setup_flow.h" | 5 #include "chrome/browser/local_discovery/privetv3_setup_flow.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/local_discovery/gcd_api_flow.h" | 9 #include "chrome/browser/local_discovery/gcd_api_flow.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 MOCK_METHOD1(GetWiFiCredentials, void(const CredentialsCallback&)); | 88 MOCK_METHOD1(GetWiFiCredentials, void(const CredentialsCallback&)); |
| 89 MOCK_METHOD1(SwitchToSetupWiFi, void(const ResultCallback&)); | 89 MOCK_METHOD1(SwitchToSetupWiFi, void(const ResultCallback&)); |
| 90 virtual void CreatePrivetV3Client( | 90 virtual void CreatePrivetV3Client( |
| 91 const std::string& service_name, | 91 const std::string& service_name, |
| 92 const PrivetClientCallback& callback) override { | 92 const PrivetClientCallback& callback) override { |
| 93 scoped_ptr<MockPrivetHTTPClient> privet_client(new MockPrivetHTTPClient()); | 93 scoped_ptr<MockPrivetHTTPClient> privet_client(new MockPrivetHTTPClient()); |
| 94 privet_client_ptr_ = privet_client.get(); | 94 privet_client_ptr_ = privet_client.get(); |
| 95 callback.Run(privet_client.Pass()); | 95 callback.Run(privet_client.Pass()); |
| 96 } | 96 } |
| 97 MOCK_METHOD2(ConfirmSecurityCode, | 97 MOCK_METHOD1(ConfirmSecurityCode, void(const ResultCallback&)); |
| 98 void(const std::string&, const ResultCallback&)); | |
| 99 MOCK_METHOD1(RestoreWifi, void(const ResultCallback&)); | 98 MOCK_METHOD1(RestoreWifi, void(const ResultCallback&)); |
| 100 MOCK_METHOD0(OnSetupDone, void()); | 99 MOCK_METHOD0(OnSetupDone, void()); |
| 101 MOCK_METHOD0(OnSetupError, void()); | 100 MOCK_METHOD0(OnSetupError, void()); |
| 102 | 101 |
| 103 virtual scoped_ptr<GCDApiFlow> CreateApiFlow() override { | 102 virtual scoped_ptr<GCDApiFlow> CreateApiFlow() override { |
| 104 return make_scoped_ptr(new MockGCDApiFlow(this)); | 103 return make_scoped_ptr(new MockGCDApiFlow(this)); |
| 105 } | 104 } |
| 106 | 105 |
| 107 void ReplyWithToken() { | 106 void ReplyWithToken() { |
| 108 scoped_ptr<base::Value> value(base::JSONReader::Read(gcd_server_response_)); | 107 scoped_ptr<base::Value> value(base::JSONReader::Read(gcd_server_response_)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 126 void ConfirmCode(const MockDelegate::ResultCallback& confirm_callback) { | 125 void ConfirmCode(const MockDelegate::ResultCallback& confirm_callback) { |
| 127 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 126 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); |
| 128 confirm_callback.Run(true); | 127 confirm_callback.Run(true); |
| 129 } | 128 } |
| 130 | 129 |
| 131 protected: | 130 protected: |
| 132 virtual void SetUp() override { | 131 virtual void SetUp() override { |
| 133 quit_closure_ = run_loop_.QuitClosure(); | 132 quit_closure_ = run_loop_.QuitClosure(); |
| 134 EXPECT_CALL(delegate_, GetWiFiCredentials(_)).Times(0); | 133 EXPECT_CALL(delegate_, GetWiFiCredentials(_)).Times(0); |
| 135 EXPECT_CALL(delegate_, SwitchToSetupWiFi(_)).Times(0); | 134 EXPECT_CALL(delegate_, SwitchToSetupWiFi(_)).Times(0); |
| 136 EXPECT_CALL(delegate_, ConfirmSecurityCode(_, _)).Times(0); | 135 EXPECT_CALL(delegate_, ConfirmSecurityCode(_)).Times(0); |
| 137 EXPECT_CALL(delegate_, RestoreWifi(_)).Times(0); | 136 EXPECT_CALL(delegate_, RestoreWifi(_)).Times(0); |
| 138 EXPECT_CALL(delegate_, OnSetupDone()).Times(0); | 137 EXPECT_CALL(delegate_, OnSetupDone()).Times(0); |
| 139 EXPECT_CALL(delegate_, OnSetupError()).Times(0); | 138 EXPECT_CALL(delegate_, OnSetupError()).Times(0); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void SimulateFetch(int response_code, const std::string& response) { | 141 void SimulateFetch(int response_code, const std::string& response) { |
| 143 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 142 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 144 ASSERT_TRUE(fetcher); | 143 ASSERT_TRUE(fetcher); |
| 145 EXPECT_THAT(fetcher->GetOriginalURL().spec(), | 144 EXPECT_THAT(fetcher->GetOriginalURL().spec(), |
| 146 testing::HasSubstr("/privet/v3/setup/start")); | 145 testing::HasSubstr("/privet/v3/setup/start")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 162 }; | 161 }; |
| 163 | 162 |
| 164 TEST_F(PrivetV3SetupFlowTest, InvalidTicket) { | 163 TEST_F(PrivetV3SetupFlowTest, InvalidTicket) { |
| 165 EXPECT_CALL(delegate_, OnSetupError()).Times(1); | 164 EXPECT_CALL(delegate_, OnSetupError()).Times(1); |
| 166 delegate_.gcd_server_response_ = "{}"; | 165 delegate_.gcd_server_response_ = "{}"; |
| 167 setup_.Register(kServiceName); | 166 setup_.Register(kServiceName); |
| 168 } | 167 } |
| 169 | 168 |
| 170 TEST_F(PrivetV3SetupFlowTest, InvalidDeviceResponce) { | 169 TEST_F(PrivetV3SetupFlowTest, InvalidDeviceResponce) { |
| 171 EXPECT_CALL(delegate_, OnSetupError()).Times(1); | 170 EXPECT_CALL(delegate_, OnSetupError()).Times(1); |
| 172 EXPECT_CALL(delegate_, ConfirmSecurityCode(_, _)).Times(1).WillOnce( | 171 EXPECT_CALL(delegate_, ConfirmSecurityCode(_)) |
| 173 WithArgs<1>(Invoke(this, &PrivetV3SetupFlowTest::ConfirmCode))); | 172 .Times(1) |
| 173 .WillOnce(WithArgs<0>(Invoke(this, &PrivetV3SetupFlowTest::ConfirmCode))); |
| 174 delegate_.gcd_server_response_ = kRegistrationTicketResponse; | 174 delegate_.gcd_server_response_ = kRegistrationTicketResponse; |
| 175 setup_.Register(kServiceName); | 175 setup_.Register(kServiceName); |
| 176 run_loop_.Run(); | 176 run_loop_.Run(); |
| 177 SimulateFetch(0, "{}"); | 177 SimulateFetch(0, "{}"); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST_F(PrivetV3SetupFlowTest, Success) { | 180 TEST_F(PrivetV3SetupFlowTest, Success) { |
| 181 EXPECT_CALL(delegate_, OnSetupDone()).Times(1); | 181 EXPECT_CALL(delegate_, OnSetupDone()).Times(1); |
| 182 EXPECT_CALL(delegate_, ConfirmSecurityCode(_, _)).Times(1).WillOnce( | 182 EXPECT_CALL(delegate_, ConfirmSecurityCode(_)) |
| 183 WithArgs<1>(Invoke(this, &PrivetV3SetupFlowTest::ConfirmCode))); | 183 .Times(1) |
| 184 .WillOnce(WithArgs<0>(Invoke(this, &PrivetV3SetupFlowTest::ConfirmCode))); |
| 184 delegate_.gcd_server_response_ = kRegistrationTicketResponse; | 185 delegate_.gcd_server_response_ = kRegistrationTicketResponse; |
| 185 setup_.Register(kServiceName); | 186 setup_.Register(kServiceName); |
| 186 run_loop_.Run(); | 187 run_loop_.Run(); |
| 187 SimulateFetch(200, "{}"); | 188 SimulateFetch(200, "{}"); |
| 188 } | 189 } |
| 189 | 190 |
| 190 } // namespace | 191 } // namespace |
| 191 | 192 |
| 192 } // namespace local_discovery | 193 } // namespace local_discovery |
| OLD | NEW |