disable two ClientCertStoreChromeOSTest.* unit_tests on Valgrind bots
[chromium-blink-merge.git] / sync / internal_api / attachments / fake_attachment_uploader_unittest.cc
blob5d86ad483b08299eb480443b64d7d52b14a96f61
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
3 // found in the LICENSE file.
5 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h"
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/ref_counted_memory.h"
10 #include "base/run_loop.h"
11 #include "sync/api/attachments/attachment.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace syncer {
16 namespace {
18 const char kAttachmentData[] = "some data";
20 } // namespace
22 class FakeAttachmentUploaderTest : public testing::Test {
23 protected:
24 void SetUp() override {
25 upload_callback_count = 0;
26 upload_callback = base::Bind(&FakeAttachmentUploaderTest::Increment,
27 base::Unretained(this),
28 &upload_callback_count);
30 base::MessageLoop message_loop;
31 FakeAttachmentUploader uploader;
32 int upload_callback_count;
33 AttachmentUploader::UploadCallback upload_callback;
35 private:
36 void Increment(int* success_count,
37 const AttachmentUploader::UploadResult& result,
38 const AttachmentId& ignored) {
39 if (result == AttachmentUploader::UPLOAD_SUCCESS) {
40 ++(*success_count);
45 // Call upload attachment several times, see that the supplied callback is
46 // invoked the same number of times with a result of SUCCESS.
47 TEST_F(FakeAttachmentUploaderTest, UploadAttachment) {
48 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString);
49 some_data->data() = kAttachmentData;
50 Attachment attachment1 = Attachment::Create(some_data);
51 Attachment attachment2 = Attachment::Create(some_data);
52 Attachment attachment3 = Attachment::Create(some_data);
53 uploader.UploadAttachment(attachment1, upload_callback);
54 uploader.UploadAttachment(attachment2, upload_callback);
55 uploader.UploadAttachment(attachment3, upload_callback);
56 base::RunLoop().RunUntilIdle();
57 EXPECT_EQ(upload_callback_count, 3);
60 } // namespace syncer