Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1382)

Unified Diff: third_party/cacheinvalidation/src/google/cacheinvalidation/impl/invalidation-client-factory_test.cc

Issue 1162033004: Pull cacheinvalidations code directory into chromium repo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/cacheinvalidation/src/google/cacheinvalidation/impl/invalidation-client-factory_test.cc
diff --git a/third_party/cacheinvalidation/src/google/cacheinvalidation/impl/invalidation-client-factory_test.cc b/third_party/cacheinvalidation/src/google/cacheinvalidation/impl/invalidation-client-factory_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea5166492addb647a56ed685a488642eb59c79a8
--- /dev/null
+++ b/third_party/cacheinvalidation/src/google/cacheinvalidation/impl/invalidation-client-factory_test.cc
@@ -0,0 +1,114 @@
+// Copyright 2013 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Unit tests for the InvalidationClientFactory class.
+
+#include "google/cacheinvalidation/include/invalidation-client-factory.h"
+#include "google/cacheinvalidation/include/invalidation-listener.h"
+#include "google/cacheinvalidation/include/types.h"
+#include "google/cacheinvalidation/types.pb.h"
+#include "google/cacheinvalidation/deps/googletest.h"
+#include "google/cacheinvalidation/impl/basic-system-resources.h"
+#include "google/cacheinvalidation/impl/constants.h"
+#include "google/cacheinvalidation/impl/invalidation-client-impl.h"
+
+#include "google/cacheinvalidation/test/test-utils.h"
+
+namespace invalidation {
+
+using ::ipc::invalidation::ClientType_Type_TEST;
+using ::ipc::invalidation::ObjectSource_Type_TEST;
+using ::testing::StrictMock;
+
+// Test constants
+static const char CLIENT_NAME[] = "demo-client-01";
+static const char APPLICATION_NAME[] = "demo-app";
+
+// Tests the basic functionality of the invalidation client factory.
+class InvalidationClientFactoryTest : public UnitTestBase {
+ public:
+ virtual ~InvalidationClientFactoryTest() {}
+
+ // Performs setup for client factory unit tests, e.g. creating resource
+ // components and setting up common expectations for certain mock objects.
+ virtual void SetUp() {
+ UnitTestBase::SetUp();
+ InitCommonExpectations(); // Set up expectations for common mock operations
+
+ // Set up the listener scheduler to run any runnable that it receives.
+ EXPECT_CALL(*listener_scheduler, Schedule(_, _))
+ .WillRepeatedly(InvokeAndDeleteClosure<1>());
+ }
+
+ // Creates a client with the given value for allowSuppression.
+ // The caller owns the storage.
+ InvalidationClientImpl* CreateClient(bool allowSuppression) {
+ InvalidationClientConfig config(ClientType_Type_TEST,
+ CLIENT_NAME, APPLICATION_NAME, allowSuppression);
+ return static_cast<InvalidationClientImpl*>(
+ ClientFactory::Create(resources.get(), config, &listener));
+ }
+
+ // Verifies that a client has expected values for allowing suppression
+ // and application client id.
+ void CheckClientValid(const InvalidationClientImpl* client,
+ bool allowSuppression) {
+ // Check that the the allow suppression flag was correctly set to
+ // the expected value.
+ ClientConfigP config = client->config_;
+ ASSERT_EQ(allowSuppression, config.allow_suppression());
+
+ // Check that the client type and client name were properly populated.
+ ASSERT_EQ(ClientType_Type_TEST,
+ client->application_client_id_.client_type());
+
+ ASSERT_EQ(CLIENT_NAME,
+ client->application_client_id_.client_name());
+ }
+
+ // The client being tested. Created fresh for each test function.
+ scoped_ptr<InvalidationClientImpl> client;
+
+ // A mock invalidation listener.
+ StrictMock<MockInvalidationListener> listener;
+};
+
+// Tests that the deprecated CreateInvalidationClient overload
+// correctly initializes the client to allow suppression.
+TEST_F(InvalidationClientFactoryTest, TestCreateClient) {
+ client.reset(static_cast<InvalidationClientImpl*>(
+ CreateInvalidationClient(
+ resources.get(),
+ ClientType_Type_TEST,
+ CLIENT_NAME,
+ APPLICATION_NAME,
+ &listener)));
+ CheckClientValid(client.get(), true /* allowSuppression */);
+}
+
+// Tests CreateClient with allowSuppression = false.
+TEST_F(InvalidationClientFactoryTest, TestCreateClientForTrickles) {
+ bool allowSuppression = false;
+ client.reset(CreateClient(allowSuppression));
+ CheckClientValid(client.get(), allowSuppression);
+}
+
+// Tests CreateClient with allowSuppression = true.
+TEST_F(InvalidationClientFactoryTest, testCreateClientForInvalidation) {
+ bool allowSuppression = true;
+ client.reset(CreateClient(allowSuppression));
+ CheckClientValid(client.get(), allowSuppression);
+}
+
+} // namespace invalidation

Powered by Google App Engine
This is Rietveld 408576698