content_serialized_navigation_driver_unittest.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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
  3. // found in the LICENSE file.
  4. #include "components/sessions/content/content_serialized_navigation_driver.h"
  5. #include "components/sessions/core/serialized_navigation_entry.h"
  6. #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace sessions {
  9. // Tests that PageState data is properly sanitized when post data is present.
  10. TEST(ContentSerializedNavigationDriverTest, PickleSanitizationWithPostData) {
  11. ContentSerializedNavigationDriver* driver =
  12. ContentSerializedNavigationDriver::GetInstance();
  13. SerializedNavigationEntry navigation =
  14. SerializedNavigationEntryTestHelper::CreateNavigationForTest();
  15. ASSERT_TRUE(navigation.has_post_data());
  16. // When post data is present, the page state should be sanitized.
  17. std::string sanitized_page_state =
  18. driver->GetSanitizedPageStateForPickle(&navigation);
  19. EXPECT_EQ(std::string(), sanitized_page_state);
  20. }
  21. // Tests that PageState data is left unsanitized when post data is absent.
  22. TEST(ContentSerializedNavigationDriverTest, PickleSanitizationNoPostData) {
  23. ContentSerializedNavigationDriver* driver =
  24. ContentSerializedNavigationDriver::GetInstance();
  25. SerializedNavigationEntry navigation =
  26. SerializedNavigationEntryTestHelper::CreateNavigationForTest();
  27. SerializedNavigationEntryTestHelper::SetHasPostData(false, &navigation);
  28. ASSERT_FALSE(navigation.has_post_data());
  29. std::string sanitized_page_state =
  30. driver->GetSanitizedPageStateForPickle(&navigation);
  31. EXPECT_EQ(test_data::kEncodedPageState, sanitized_page_state);
  32. }
  33. } // namespace sessions