Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / policy / auto_enrollment_client_unittest.cc
index 3e703bc..91751eb 100644 (file)
@@ -34,6 +34,7 @@ const char* kSerialHash =
     "\x6f\x02\x4a\xd7\xeb\x92\x45\xfc\xd4\xe4\x37\xa1\x55\x2b\x13\x8a";
 
 using ::testing::InSequence;
+using ::testing::Mock;
 using ::testing::SaveArg;
 using ::testing::_;
 
@@ -452,6 +453,35 @@ TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterNetworkFailure) {
   EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting());
 }
 
+TEST_F(AutoEnrollmentClientTest, NetworkFailureThenRequireUpdatedModulus) {
+  // This test verifies that if the first request fails due to a network
+  // problem then the second request will correctly handle an updated
+  // modulus request from the server.
+
+  ServerWillFail(DM_STATUS_REQUEST_FAILED);
+  client_->Start();
+  EXPECT_FALSE(client_->should_auto_enroll());
+  // Don't invoke the callback if there was a network failure.
+  EXPECT_EQ(0, completion_callback_count_);
+  EXPECT_FALSE(HasCachedDecision());
+  Mock::VerifyAndClearExpectations(service_.get());
+
+  InSequence sequence;
+  // The default client uploads 4 bits. Make the server ask for 5.
+  ServerWillReply(1 << 5, false, false);
+  EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _));
+  // Then reply with a valid response and include the hash.
+  ServerWillReply(-1, true, true);
+  EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _));
+
+  // Trigger a network change event.
+  client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
+  EXPECT_TRUE(client_->should_auto_enroll());
+  EXPECT_EQ(1, completion_callback_count_);
+  EXPECT_TRUE(HasCachedDecision());
+  Mock::VerifyAndClearExpectations(service_.get());
+}
+
 }  // namespace
 
 }  // namespace policy