Resize destination bus to the actual number of decoded frames.
[chromium-blink-merge.git] / sync / engine / store_timestamps_command_unittest.cc
blobe49eb3126eed11810250d5988c67da4021eb8422
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "sync/engine/store_timestamps_command.h"
7 #include "sync/internal_api/public/base/model_type.h"
8 #include "sync/protocol/sync.pb.h"
9 #include "sync/test/engine/syncer_command_test.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace syncer {
14 namespace {
16 // Adds a progress marker to |response| for the given field number and
17 // token.
18 void AddProgressMarkerForFieldNumber(
19 sync_pb::GetUpdatesResponse* response,
20 int field_number, const std::string& token) {
21 sync_pb::DataTypeProgressMarker* marker =
22 response->add_new_progress_marker();
23 marker->set_data_type_id(field_number);
24 marker->set_token(token);
27 // Adds a progress marker to |response| for the given model type and
28 // token.
29 void AddProgressMarkerForModelType(
30 sync_pb::GetUpdatesResponse* response,
31 ModelType model_type, const std::string& token) {
32 AddProgressMarkerForFieldNumber(
33 response, GetSpecificsFieldNumberFromModelType(model_type), token);
36 class StoreTimestampsCommandTest : public SyncerCommandTest {
37 protected:
38 // Gets the directory's progress marker's token for the given model
39 // type.
40 std::string GetProgessMarkerToken(ModelType model_type) {
41 sync_pb::DataTypeProgressMarker progress_marker;
42 session()->context()->directory()->GetDownloadProgress(
43 model_type, &progress_marker);
44 EXPECT_EQ(
45 GetSpecificsFieldNumberFromModelType(model_type),
46 progress_marker.data_type_id());
47 return progress_marker.token();
51 // Builds a GetUpdatesResponse with some progress markers, including
52 // invalid ones. ProcessNewProgressMarkers() should return the model
53 // types for the valid progress markers and fill in the progress
54 // markers in the directory.
55 TEST_F(StoreTimestampsCommandTest, ProcessNewProgressMarkers) {
56 sync_pb::GetUpdatesResponse response;
57 AddProgressMarkerForModelType(&response, BOOKMARKS, "token1");
58 AddProgressMarkerForModelType(&response,
59 HISTORY_DELETE_DIRECTIVES, "token2");
60 AddProgressMarkerForFieldNumber(&response, -1, "bad token");
62 ModelTypeSet forward_progress_types =
63 ProcessNewProgressMarkers(
64 response, session()->context()->directory());
66 EXPECT_TRUE(
67 forward_progress_types.Equals(
68 ModelTypeSet(BOOKMARKS, HISTORY_DELETE_DIRECTIVES)));
70 EXPECT_EQ("token1", GetProgessMarkerToken(BOOKMARKS));
71 EXPECT_EQ("token2", GetProgessMarkerToken(HISTORY_DELETE_DIRECTIVES));
73 ModelTypeSet non_forward_progress_types =
74 Difference(ProtocolTypes(), forward_progress_types);
75 for (ModelTypeSet::Iterator it = non_forward_progress_types.First();
76 it.Good(); it.Inc()) {
77 EXPECT_TRUE(GetProgessMarkerToken(it.Get()).empty());
81 } // namespace
83 } // namespace syncer