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

Side by Side Diff: content/browser/accessibility/android_granularity_movement_browsertest.cc

Issue 1182183003: Move EndsWith to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | content/browser/plugin_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 static_cast<BrowserAccessibilityManagerAndroid*>(node->manager()); 84 static_cast<BrowserAccessibilityManagerAndroid*>(node->manager());
85 base::string16 text = android_node->GetText(); 85 base::string16 text = android_node->GetText();
86 base::string16 concatenated; 86 base::string16 concatenated;
87 int previous_end_index = -1; 87 int previous_end_index = -1;
88 while (manager->NextAtGranularity( 88 while (manager->NextAtGranularity(
89 granularity, end_index, android_node, 89 granularity, end_index, android_node,
90 &start_index, &end_index)) { 90 &start_index, &end_index)) {
91 int len = (granularity == GRANULARITY_CHARACTER) ? 91 int len = (granularity == GRANULARITY_CHARACTER) ?
92 1 : end_index - start_index; 92 1 : end_index - start_index;
93 base::string16 selection = text.substr(start_index, len); 93 base::string16 selection = text.substr(start_index, len);
94 if (EndsWith(selection, base::ASCIIToUTF16("\n"), false)) 94 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), false))
95 selection.erase(selection.size() - 1); 95 selection.erase(selection.size() - 1);
96 if (!selection.empty()) { 96 if (!selection.empty()) {
97 if (!concatenated.empty()) 97 if (!concatenated.empty())
98 concatenated += base::ASCIIToUTF16(", "); 98 concatenated += base::ASCIIToUTF16(", ");
99 concatenated += base::ASCIIToUTF16("'") + selection + 99 concatenated += base::ASCIIToUTF16("'") + selection +
100 base::ASCIIToUTF16("'"); 100 base::ASCIIToUTF16("'");
101 } 101 }
102 102
103 // Prevent an endless loop. 103 // Prevent an endless loop.
104 if (end_index == previous_end_index) { 104 if (end_index == previous_end_index) {
105 LOG(ERROR) << "Bailing from loop, NextAtGranularity didn't advance"; 105 LOG(ERROR) << "Bailing from loop, NextAtGranularity didn't advance";
106 break; 106 break;
107 } 107 }
108 previous_end_index = end_index; 108 previous_end_index = end_index;
109 } 109 }
110 110
111 base::string16 reverse; 111 base::string16 reverse;
112 previous_end_index = -1; 112 previous_end_index = -1;
113 start_index = end_index; 113 start_index = end_index;
114 while (manager->PreviousAtGranularity( 114 while (manager->PreviousAtGranularity(
115 granularity, start_index, android_node, &start_index, &end_index)) { 115 granularity, start_index, android_node, &start_index, &end_index)) {
116 int len = (granularity == GRANULARITY_CHARACTER) ? 116 int len = (granularity == GRANULARITY_CHARACTER) ?
117 1 : end_index - start_index; 117 1 : end_index - start_index;
118 base::string16 selection = text.substr(start_index, len); 118 base::string16 selection = text.substr(start_index, len);
119 if (EndsWith(selection, base::ASCIIToUTF16("\n"), false)) 119 if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), false))
120 selection = selection.substr(0, selection.size() - 1); 120 selection = selection.substr(0, selection.size() - 1);
121 if (!reverse.empty()) 121 if (!reverse.empty())
122 reverse = base::ASCIIToUTF16(", ") + reverse; 122 reverse = base::ASCIIToUTF16(", ") + reverse;
123 reverse = base::ASCIIToUTF16("'") + selection + 123 reverse = base::ASCIIToUTF16("'") + selection +
124 base::ASCIIToUTF16("'") + reverse; 124 base::ASCIIToUTF16("'") + reverse;
125 125
126 // Prevent an endless loop. 126 // Prevent an endless loop.
127 if (end_index == previous_end_index) { 127 if (end_index == previous_end_index) {
128 LOG(ERROR) << "Bailing from loop, PreviousAtGranularity didn't advance"; 128 LOG(ERROR) << "Bailing from loop, PreviousAtGranularity didn't advance";
129 break; 129 break;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url); 200 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url);
201 ASSERT_EQ(1U, root->PlatformChildCount()); 201 ASSERT_EQ(1U, root->PlatformChildCount());
202 BrowserAccessibility* pre = root->PlatformGetChild(0); 202 BrowserAccessibility* pre = root->PlatformGetChild(0);
203 ASSERT_EQ(0U, pre->PlatformChildCount()); 203 ASSERT_EQ(0U, pre->PlatformChildCount());
204 204
205 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"), 205 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"),
206 TraverseNodeAtGranularity(pre, GRANULARITY_LINE)); 206 TraverseNodeAtGranularity(pre, GRANULARITY_LINE));
207 } 207 }
208 208
209 } // namespace content 209 } // namespace content
OLDNEW
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | content/browser/plugin_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698