1 // Copyright (c) 2013 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. 4 5 #include "base/strings/utf_string_conversions.h" 6 #include "content/public/common/context_menu_params.h" 7 #include "content/renderer/render_view_impl.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "ui/gfx/range/range.h" 10 11 namespace content { 12 13 TEST(RenderViewImplTest, ShouldUpdateSelectionTextFromContextMenuParams) { 14 struct { 15 const char* selection_text; 16 size_t selection_text_offset; 17 gfx::Range selection_range; 18 const char* params_selection_text; 19 bool expected_result; 20 } cases[] = { 21 { "test", 0, gfx::Range(0, 4), "test", false }, 22 { "zebestest", 0, gfx::Range(2, 6), "best", false }, 23 { "zebestest", 2, gfx::Range(2, 6), "best", true }, 24 { "test", 0, gfx::Range(0, 4), "hello", true }, 25 { "best test", 0, gfx::Range(0, 4), "best ", false }, 26 { "best test", 0, gfx::Range(0, 5), "best", false }, 27 }; 28 29 ContextMenuParams params; 30 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 31 params.selection_text = UTF8ToUTF16(cases[i].params_selection_text); 32 EXPECT_EQ(cases[i].expected_result, 33 RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams( 34 UTF8ToUTF16(cases[i].selection_text), 35 cases[i].selection_text_offset, 36 cases[i].selection_range, 37 params)); 38 } 39 } 40 41 } // namespace content 42