From 06bc30a802663f6be22e99d4cc62edf9b345d77a Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 4 Jun 2012 17:03:31 +0000 Subject: [PATCH] Clear the input array passed to CefBrowser::GetFrameIdentifiers so that the correct values are returned via the C/C++ wrapper API, and add a test (issue #626). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@665 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser/browser_host_impl.cc | 6 +++++ tests/unittests/navigation_unittest.cc | 34 +++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 87479efe7..412463a14 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -434,6 +434,9 @@ size_t CefBrowserHostImpl::GetFrameCount() { void CefBrowserHostImpl::GetFrameIdentifiers(std::vector& identifiers) { base::AutoLock lock_scope(state_lock_); + if (identifiers.size() > 0) + identifiers.clear(); + FrameMap::const_iterator it = frames_.begin(); for (; it != frames_.end(); ++it) identifiers.push_back(it->first); @@ -442,6 +445,9 @@ void CefBrowserHostImpl::GetFrameIdentifiers(std::vector& identifiers) { void CefBrowserHostImpl::GetFrameNames(std::vector& names) { base::AutoLock lock_scope(state_lock_); + if (names.size() > 0) + names.clear(); + FrameMap::const_iterator it = frames_.begin(); for (; it != frames_.end(); ++it) names.push_back(it->second->GetName()); diff --git a/tests/unittests/navigation_unittest.cc b/tests/unittests/navigation_unittest.cc index b3713852b..a830314ff 100644 --- a/tests/unittests/navigation_unittest.cc +++ b/tests/unittests/navigation_unittest.cc @@ -242,20 +242,26 @@ class FrameNameIdentNavTestHandler : public TestHandler { std::string url = request->GetURL(); if (url == kNav1) { frame1_ident_ = frame->GetIdentifier(); - if (name == "") + if (name == "") { + frame1_name_ = name; got_frame1_name_.yes(); + } if (!parent.get()) got_frame1_ident_parent_before_.yes(); } else if (url == kNav2) { frame2_ident_ = frame->GetIdentifier(); - if (name == "nav2") + if (name == "nav2") { + frame2_name_ = name; got_frame2_name_.yes(); + } if (parent.get() && frame1_ident_ == parent->GetIdentifier()) got_frame2_ident_parent_before_.yes(); } else if (url == kNav3) { frame3_ident_ = frame->GetIdentifier(); - if (name == "-->") + if (name == "-->") { + frame3_name_ = name; got_frame3_name_.yes(); + } if (parent.get() && frame2_ident_ == parent->GetIdentifier()) got_frame3_ident_parent_before_.yes(); } @@ -286,15 +292,35 @@ class FrameNameIdentNavTestHandler : public TestHandler { got_frame3_ident_parent_after_.yes(); } - if (++browse_ct_ == 3) + if (++browse_ct_ == 3) { + // Test GetFrameNames + std::vector names; + browser->GetFrameNames(names); + EXPECT_EQ((size_t)3, names.size()); + EXPECT_STREQ(frame1_name_.c_str(), names[0].ToString().c_str()); + EXPECT_STREQ(frame2_name_.c_str(), names[1].ToString().c_str()); + EXPECT_STREQ(frame3_name_.c_str(), names[2].ToString().c_str()); + + // Test GetFrameIdentifiers + std::vector idents; + browser->GetFrameIdentifiers(idents); + EXPECT_EQ((size_t)3, idents.size()); + EXPECT_EQ(frame1_ident_, idents[0]); + EXPECT_EQ(frame2_ident_, idents[1]); + EXPECT_EQ(frame3_ident_, idents[2]); + DestroyTest(); + } } int browse_ct_; int64 frame1_ident_; + std::string frame1_name_; int64 frame2_ident_; + std::string frame2_name_; int64 frame3_ident_; + std::string frame3_name_; TrackCallback got_frame1_name_; TrackCallback got_frame2_name_;