From fc221f4f4ec62224cdb5371c75d0e0802ac0e726 Mon Sep 17 00:00:00 2001 From: erg Date: Wed, 10 Feb 2016 12:17:24 -0800 Subject: mojo: Now that mandoline/ is deleted, also remove mojo:clipboard. This was only used from within mandoline. BUG=585637 Review URL: https://codereview.chromium.org/1685953002 Cr-Commit-Position: refs/heads/master@{#374710} --- components/clipboard/clipboard_apptest.cc | 162 ------------------------------ 1 file changed, 162 deletions(-) delete mode 100644 components/clipboard/clipboard_apptest.cc (limited to 'components/clipboard/clipboard_apptest.cc') diff --git a/components/clipboard/clipboard_apptest.cc b/components/clipboard/clipboard_apptest.cc deleted file mode 100644 index 01b85cd..0000000 --- a/components/clipboard/clipboard_apptest.cc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include -#include - -#include "base/bind.h" -#include "base/macros.h" -#include "base/run_loop.h" -#include "components/clipboard/public/interfaces/clipboard.mojom.h" -#include "mojo/common/common_type_converters.h" -#include "mojo/shell/public/cpp/application_test_base.h" -#include "mojo/shell/public/cpp/shell.h" - -using mojo::Array; -using mojo::Clipboard; -using mojo::Map; -using mojo::String; - -namespace { - -void CopyUint64AndEndRunloop(uint64_t* output, - base::RunLoop* run_loop, - uint64_t input) { - *output = input; - run_loop->Quit(); -} - -void CopyStringAndEndRunloop(std::string* output, - bool* string_is_null, - base::RunLoop* run_loop, - const Array& input) { - *string_is_null = input.is_null(); - *output = input.is_null() ? "" : input.To(); - run_loop->Quit(); -} - -void CopyVectorStringAndEndRunloop(std::vector* output, - base::RunLoop* run_loop, - const Array& input) { - *output = input.To >(); - run_loop->Quit(); -} - -const char* kUninitialized = "Uninitialized data"; -const char* kPlainTextData = "Some plain data"; -const char* kHtmlData = "data"; - -} // namespace - -namespace clipboard { - -class ClipboardAppTest : public mojo::test::ApplicationTestBase { - public: - ClipboardAppTest() : ApplicationTestBase() {} - ~ClipboardAppTest() override {} - - void SetUp() override { - mojo::test::ApplicationTestBase::SetUp(); - shell()->ConnectToInterface("mojo:clipboard", &clipboard_); - } - - uint64_t GetSequenceNumber() { - base::RunLoop run_loop; - uint64_t sequence_num = 999999; - clipboard_->GetSequenceNumber( - Clipboard::Type::COPY_PASTE, - base::Bind(&CopyUint64AndEndRunloop, &sequence_num, &run_loop)); - run_loop.Run(); - return sequence_num; - } - - std::vector GetAvailableFormatMimeTypes() { - base::RunLoop run_loop; - std::vector types; - types.push_back(kUninitialized); - clipboard_->GetAvailableMimeTypes( - Clipboard::Type::COPY_PASTE, - base::Bind(&CopyVectorStringAndEndRunloop, &types, &run_loop)); - run_loop.Run(); - return types; - } - - bool GetDataOfType(const std::string& mime_type, std::string* data) { - base::RunLoop run_loop; - bool is_null = false; - clipboard_->ReadMimeType( - Clipboard::Type::COPY_PASTE, mime_type, - base::Bind(&CopyStringAndEndRunloop, data, &is_null, &run_loop)); - run_loop.Run(); - return !is_null; - } - - void SetStringText(const std::string& data) { - Map> mime_data; - mime_data[Clipboard::MIME_TYPE_TEXT] = Array::From(data); - clipboard_->WriteClipboardData(Clipboard::Type::COPY_PASTE, - std::move(mime_data)); - } - - protected: - mojo::ClipboardPtr clipboard_; - - DISALLOW_COPY_AND_ASSIGN(ClipboardAppTest); -}; - -TEST_F(ClipboardAppTest, EmptyClipboardOK) { - EXPECT_EQ(0ul, GetSequenceNumber()); - EXPECT_TRUE(GetAvailableFormatMimeTypes().empty()); - std::string data; - EXPECT_FALSE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data)); -} - -TEST_F(ClipboardAppTest, CanReadBackText) { - std::string data; - EXPECT_FALSE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data)); - EXPECT_EQ(0ul, GetSequenceNumber()); - - SetStringText(kPlainTextData); - EXPECT_EQ(1ul, GetSequenceNumber()); - - EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data)); - EXPECT_EQ(kPlainTextData, data); -} - -TEST_F(ClipboardAppTest, CanSetMultipleDataTypesAtOnce) { - Map> mime_data; - mime_data[Clipboard::MIME_TYPE_TEXT] = - Array::From(std::string(kPlainTextData)); - mime_data[Clipboard::MIME_TYPE_HTML] = - Array::From(std::string(kHtmlData)); - - clipboard_->WriteClipboardData(Clipboard::Type::COPY_PASTE, - std::move(mime_data)); - - EXPECT_EQ(1ul, GetSequenceNumber()); - - std::string data; - EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data)); - EXPECT_EQ(kPlainTextData, data); - EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_HTML, &data)); - EXPECT_EQ(kHtmlData, data); -} - -TEST_F(ClipboardAppTest, CanClearClipboardWithZeroArray) { - std::string data; - SetStringText(kPlainTextData); - EXPECT_EQ(1ul, GetSequenceNumber()); - - EXPECT_TRUE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data)); - EXPECT_EQ(kPlainTextData, data); - - Map> mime_data; - clipboard_->WriteClipboardData(Clipboard::Type::COPY_PASTE, - std::move(mime_data)); - - EXPECT_EQ(2ul, GetSequenceNumber()); - EXPECT_FALSE(GetDataOfType(Clipboard::MIME_TYPE_TEXT, &data)); -} - -} // namespace clipboard -- cgit v1.1