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

Side by Side Diff: components/sync_driver/generic_change_processor_unittest.cc

Issue 272043002: Invoke AttachmentUploader and update AttachmentIds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize through SyncApiComponentFactory Created 6 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 unified diff | Download patch
OLDNEW
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 "components/sync_driver/generic_change_processor.h" 5 #include "components/sync_driver/generic_change_processor.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 12 matching lines...) Expand all
23 #include "sync/internal_api/public/user_share.h" 23 #include "sync/internal_api/public/user_share.h"
24 #include "sync/internal_api/public/write_node.h" 24 #include "sync/internal_api/public/write_node.h"
25 #include "sync/internal_api/public/write_transaction.h" 25 #include "sync/internal_api/public/write_transaction.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace browser_sync { 28 namespace browser_sync {
29 29
30 namespace { 30 namespace {
31 31
32 const char kTestData[] = "some data"; 32 const char kTestData[] = "some data";
33 const char kUrl[] = "http://attachment.server/url";
33 34
34 // A mock that keeps track of attachments passed to StoreAttachments. 35 // A mock that keeps track of attachments passed to StoreAttachments.
35 class MockAttachmentService : public syncer::AttachmentServiceImpl { 36 class MockAttachmentService : public syncer::AttachmentServiceImpl {
36 public: 37 public:
37 MockAttachmentService(); 38 MockAttachmentService();
38 virtual ~MockAttachmentService(); 39 virtual ~MockAttachmentService();
39 virtual void StoreAttachments(const syncer::AttachmentList& attachments, 40 virtual void StoreAttachments(const syncer::AttachmentList& attachments,
40 const StoreCallback& callback) OVERRIDE; 41 const StoreCallback& callback) OVERRIDE;
41 std::vector<syncer::AttachmentList>* attachment_lists(); 42 std::vector<syncer::AttachmentList>* attachment_lists();
42 43
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 340 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
340 341
341 // Check that the AttachmentService received it. 342 // Check that the AttachmentService received it.
342 ASSERT_EQ(mock_attachment_service()->attachment_lists()->size(), 1U); 343 ASSERT_EQ(mock_attachment_service()->attachment_lists()->size(), 1U);
343 const syncer::AttachmentList& new_attachments_added = 344 const syncer::AttachmentList& new_attachments_added =
344 mock_attachment_service()->attachment_lists()->front(); 345 mock_attachment_service()->attachment_lists()->front();
345 ASSERT_EQ(new_attachments_added.size(), 1U); 346 ASSERT_EQ(new_attachments_added.size(), 1U);
346 ASSERT_EQ(new_attachments_added[0].GetId(), new_attachments[0].GetId()); 347 ASSERT_EQ(new_attachments_added[0].GetId(), new_attachments[0].GetId());
347 } 348 }
348 349
350 // Verify that after attachment is uploaded GenericChangeProcessor updates
351 // corresponding entries
352 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) {
353 std::string tag = "client_tag";
354 std::string title = "client_title";
355 sync_pb::EntitySpecifics specifics;
356 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
357 pref_specifics->set_name("test");
358 syncer::AttachmentList attachments;
359 scoped_refptr<base::RefCountedString> attachment_data =
360 new base::RefCountedString;
361 attachment_data->data() = kTestData;
362 attachments.push_back(syncer::Attachment::Create(attachment_data));
363
364 // Add a SyncData with two attachments.
365 syncer::SyncChangeList change_list;
366 change_list.push_back(
367 syncer::SyncChange(FROM_HERE,
368 syncer::SyncChange::ACTION_ADD,
369 syncer::SyncData::CreateLocalDataWithAttachments(
370 tag, title, specifics, attachments)));
371 ASSERT_FALSE(
372 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
373
374 sync_pb::AttachmentIdProto attachment_id_proto =
375 attachments[0].GetId().GetProto();
376 attachment_id_proto.set_url(kUrl);
377 syncer::AttachmentId attachment_id =
378 syncer::AttachmentId::CreateFromProto(attachment_id_proto);
379
380 change_processor()->OnAttachmentUploaded(attachment_id);
381 syncer::ReadTransaction read_transaction(FROM_HERE, user_share());
382 syncer::ReadNode node(&read_transaction);
383 ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag),
384 syncer::BaseNode::INIT_OK);
385 syncer::AttachmentIdList attachment_ids = node.GetAttachmentIds();
386 EXPECT_EQ(1U, attachment_ids.size());
387 EXPECT_EQ(kUrl, attachment_ids[0].GetProto().url());
388 }
389
349 } // namespace 390 } // namespace
350 391
351 } // namespace browser_sync 392 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698