summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 16:40:54 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 16:40:54 +0000
commit509c2346d6ff600cc448fa7bf556b8227b0be6de (patch)
treedd5528ea876f82ec51d8e5cd167e03c90b6dfa35 /chrome_frame
parentcdadf6f7c36adb8f84f3661cff2e3c44d180df17 (diff)
downloadchromium_src-509c2346d6ff600cc448fa7bf556b8227b0be6de.zip
chromium_src-509c2346d6ff600cc448fa7bf556b8227b0be6de.tar.gz
chromium_src-509c2346d6ff600cc448fa7bf556b8227b0be6de.tar.bz2
Add a method for setting the value of an Accessibility object.
BUG=none TEST=none Review URL: http://codereview.chromium.org/3156026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56867 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r--chrome_frame/test/chrome_frame_ui_test_utils.cc42
-rw-r--r--chrome_frame/test/chrome_frame_ui_test_utils.h7
-rw-r--r--chrome_frame/test/mock_ie_event_sink_actions.h26
-rw-r--r--chrome_frame/test/mock_ie_event_sink_test.cc5
-rw-r--r--chrome_frame/test/ui_test.cc23
5 files changed, 85 insertions, 18 deletions
diff --git a/chrome_frame/test/chrome_frame_ui_test_utils.cc b/chrome_frame/test/chrome_frame_ui_test_utils.cc
index 63629f5..078fddc 100644
--- a/chrome_frame/test/chrome_frame_ui_test_utils.cc
+++ b/chrome_frame/test/chrome_frame_ui_test_utils.cc
@@ -13,6 +13,7 @@
#include "base/scoped_bstr_win.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "gfx/rect.h"
#include "chrome_frame/test/win_event_receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -53,6 +54,18 @@ AccObject* AccObject::CreateFromWindow(HWND hwnd) {
}
// static
+AccObject* AccObject::CreateFromEvent(HWND hwnd, LONG object_id,
+ LONG child_id) {
+ ScopedComPtr<IAccessible> accessible;
+ ScopedVariant acc_child_id;
+ AccessibleObjectFromEvent(hwnd, object_id, child_id, accessible.Receive(),
+ acc_child_id.Receive());
+ if (accessible && acc_child_id.type() == VT_I4)
+ return new AccObject(accessible, V_I4(&acc_child_id));
+ return NULL;
+}
+
+// static
AccObject* AccObject::CreateFromDispatch(IDispatch* dispatch) {
if (dispatch) {
ScopedComPtr<IAccessible> accessible;
@@ -114,6 +127,22 @@ bool AccObject::Select() {
return did_select;
}
+bool AccObject::SetValue(const std::wstring& value) {
+ ScopedBstr value_bstr(value.c_str());
+ EXPECT_HRESULT_SUCCEEDED(accessible_->put_accValue(child_id_, value_bstr));
+
+ // Double check that the object's value has actually changed. Some objects'
+ // values can not be changed.
+ bool did_set_value = false;
+ std::wstring actual_value = L"-";
+ if (GetValue(&actual_value) && value == actual_value) {
+ did_set_value = true;
+ }
+ EXPECT_TRUE(did_set_value) << "Could not set value for AccObject: "
+ << GetDescription();
+ return did_set_value;
+}
+
bool AccObject::GetName(std::wstring* name) {
DCHECK(name);
ScopedBstr name_bstr;
@@ -233,9 +262,12 @@ bool AccObject::GetChildren(RefCountedAccObjectVector* client_objects) {
objects.push_back(new AccObject(accessible_, V_I4(&children[i])));
continue;
} else if (FAILED(result)) {
- LOG(ERROR) << "Failed to determine if child id refers to a full "
- << "object. Error: " << result;
- return false;
+ DLOG(WARNING) << "Failed to determine if child id refers to a full "
+ << "object. Error: " << result << std::endl
+ << "Parent object: " << WideToUTF8(GetDescription())
+ << std::endl << "Child ID: " << V_I4(&children[i]);
+ // Disregard this object.
+ continue;
}
// The object in question was actually a full object. It is saved in the
// |dispatch| arg and will be added down below.
@@ -400,9 +432,9 @@ bool FindAccObjectInWindow(HWND hwnd, const AccObjectMatcher& matcher,
scoped_refptr<AccObject>* object) {
DCHECK(object);
EXPECT_TRUE(matcher.FindInWindow(hwnd, object));
- EXPECT_TRUE(object) << "Element not found for matcher: "
+ EXPECT_TRUE(*object) << "Element not found for matcher: "
<< matcher.GetDescription();
- if (!object)
+ if (!*object)
DumpAccessibilityTreeForWindow(hwnd);
return *object;
}
diff --git a/chrome_frame/test/chrome_frame_ui_test_utils.h b/chrome_frame/test/chrome_frame_ui_test_utils.h
index 4d254d5..3882483 100644
--- a/chrome_frame/test/chrome_frame_ui_test_utils.h
+++ b/chrome_frame/test/chrome_frame_ui_test_utils.h
@@ -40,6 +40,10 @@ class AccObject : public base::RefCounted<AccObject> {
// created AccObject.
static AccObject* CreateFromWindow(HWND hwnd);
+ // Creates an AccObject corresponding to the object that generated a
+ // WinEvent. Returns NULL on failure.
+ static AccObject* CreateFromEvent(HWND hwnd, LONG object_id, LONG child_id);
+
// Creates an AccObject from querying the given IDispatch. May return NULL
// if the object does not implement IAccessible. The client owns the created
// AccObject.
@@ -63,6 +67,9 @@ class AccObject : public base::RefCounted<AccObject> {
// test failure if the object is not selected.
bool Select();
+ // Sets the value of the object. Will cause test failure if unsuccessful.
+ bool SetValue(const std::wstring& value);
+
// Gets the name of the object and returns true on success.
bool GetName(std::wstring* name);
diff --git a/chrome_frame/test/mock_ie_event_sink_actions.h b/chrome_frame/test/mock_ie_event_sink_actions.h
index d0e46a5..56fab9f 100644
--- a/chrome_frame/test/mock_ie_event_sink_actions.h
+++ b/chrome_frame/test/mock_ie_event_sink_actions.h
@@ -7,10 +7,14 @@
#include <windows.h>
+#include "base/basictypes.h"
+#include "base/platform_thread.h"
#include "base/scoped_bstr_win.h"
+#include "base/time.h"
#include "chrome/common/chrome_switches.h"
#include "chrome_frame/test/chrome_frame_test_utils.h"
#include "chrome_frame/test/chrome_frame_ui_test_utils.h"
+#include "chrome_frame/test/ie_event_sink.h"
#include "chrome_frame/test/mock_ie_event_sink_test.h"
#include "chrome_frame/test/simulate_input.h"
#include "gfx/point.h"
@@ -216,6 +220,20 @@ ACTION_P(VerifyAddressBarUrlWithGcf, mock) {
mock->event_sink()->ExpectAddressBarUrl(expected_url);
}
+// Polls to see if the file is saved and closes the browser once it is.
+// This doesn't do any checking of the contents of the file.
+ACTION_P3(CloseWhenFileSaved, mock, file, timeout_ms) {
+ base::Time start = base::Time::Now();
+ while (!file_util::PathExists(file)) {
+ PlatformThread::Sleep(200);
+ if ((base::Time::Now() - start).InMilliseconds() > timeout_ms) {
+ ADD_FAILURE() << "File was not saved within timeout";
+ break;
+ }
+ }
+ mock->event_sink()->CloseWebBrowser();
+}
+
ACTION_P2(OpenContextMenu, loop, delay) {
loop->PostDelayedTask(FROM_HERE, NewRunnableFunction(
simulate_input::SendScanCode, VK_F10, simulate_input::SHIFT), delay);
@@ -226,7 +244,7 @@ ACTION_P3(SelectItem, loop, delay, index) {
simulate_input::NONE);
}
-ACTION(FocusAccObject) {
+ACTION(FocusWindow) {
scoped_refptr<AccObject> object;
if (FindAccObjectInWindow(arg0, AccObjectMatcher(), &object))
object->Focus();
@@ -250,6 +268,12 @@ ACTION_P(SelectAccObject, matcher) {
object->Select();
}
+ACTION_P2(SetAccObjectValue, matcher, value) {
+ scoped_refptr<AccObject> object;
+ if (FindAccObjectInWindow(arg0, matcher, &object))
+ object->SetValue(value);
+}
+
ACTION(OpenContextMenuAsync) {
// Special case this implementation because the top-left of the window is
// much more likely to be empty than the center.
diff --git a/chrome_frame/test/mock_ie_event_sink_test.cc b/chrome_frame/test/mock_ie_event_sink_test.cc
index 00eac00..b6e0146 100644
--- a/chrome_frame/test/mock_ie_event_sink_test.cc
+++ b/chrome_frame/test/mock_ie_event_sink_test.cc
@@ -200,6 +200,11 @@ void MockIEEventSinkTest::LaunchIENavigateAndLoop(const std::wstring& url,
loop_.RunFor(timeout);
}
+FilePath MockIEEventSinkTest::GetTestFilePath(
+ const std::wstring& relative_path) {
+ return server_mock_.root_dir().Append(relative_path);
+}
+
std::wstring MockIEEventSinkTest::GetTestUrl(
const std::wstring& relative_path) {
return server_mock_.Resolve(relative_path.c_str());
diff --git a/chrome_frame/test/ui_test.cc b/chrome_frame/test/ui_test.cc
index 4f615b4..3d1cf12 100644
--- a/chrome_frame/test/ui_test.cc
+++ b/chrome_frame/test/ui_test.cc
@@ -6,6 +6,7 @@
#include <string>
#include "base/scoped_variant_win.h"
+#include "base/test/test_file_util.h"
#include "chrome/common/url_constants.h"
#include "chrome_frame/test/chrome_frame_test_utils.h"
#include "chrome_frame/test/chrome_frame_ui_test_utils.h"
@@ -443,7 +444,7 @@ TEST_F(ContextMenuTest, CFInspector) {
kChromeFrameLongNavigationTimeoutInSeconds * 2);
}
-TEST_F(ContextMenuTest, FLAKY_CFSaveAs) {
+TEST_F(ContextMenuTest, CFSaveAs) {
server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
MockWindowObserver win_observer_mock;
InSequence expect_in_sequence_for_scope;
@@ -457,24 +458,22 @@ TEST_F(ContextMenuTest, FLAKY_CFSaveAs) {
EXPECT_CALL(acc_observer_, OnMenuPopup(_))
.WillOnce(DoDefaultAction(AccObjectMatcher(L"Save as...")));
+ // Get safe download name using temporary file.
FilePath temp_file_path;
- EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
+ ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
temp_file_path = temp_file_path.ReplaceExtension(L".htm");
+ ASSERT_TRUE(file_util::DieFileDie(temp_file_path, false));
- const wchar_t* kSaveFileName = temp_file_path.value().c_str();
- DeleteFile(kSaveFileName);
-
- const char* kSaveDlgCaption = "Save As";
- EXPECT_CALL(win_observer_mock, OnWindowDetected(_, StrEq(kSaveDlgCaption)))
+ EXPECT_CALL(win_observer_mock, OnWindowDetected(_, StrEq("Save As")))
.WillOnce(testing::DoAll(
- DelaySendString(&loop_, 100, kSaveFileName),
- DelaySendChar(&loop_, 200, VK_RETURN, simulate_input::NONE),
- DelayCloseBrowserMock(&loop_, 4000, &ie_mock_)));
+ SetAccObjectValue(AccObjectMatcher(L"File name:", L"", L"simple*"),
+ temp_file_path.value()),
+ DoDefaultAction(AccObjectMatcher(L"Save", L"push button")),
+ CloseWhenFileSaved(&ie_mock_, temp_file_path, 5000)));
LaunchIENavigateAndLoop(GetSimplePageUrl(),
kChromeFrameLongNavigationTimeoutInSeconds * 2);
- ASSERT_NE(INVALID_FILE_ATTRIBUTES, GetFileAttributes(kSaveFileName));
- ASSERT_TRUE(DeleteFile(kSaveFileName));
+ ASSERT_TRUE(file_util::DieFileDie(temp_file_path, false));
}
// This tests that the about:version page can be opened via the CF context menu.