Home | History | Annotate | Download | only in password_manager
      1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_DATA_H_
      6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_DATA_H_
      7 
      8 #include <ostream>
      9 
     10 #include "content/public/common/password_form.h"
     11 #include "testing/gmock/include/gmock/gmock.h"
     12 
     13 // Struct used for creation of PasswordForms from static arrays of data.
     14 // Note: This is only meant to be used in unit test.
     15 struct PasswordFormData {
     16   const content::PasswordForm::Scheme scheme;
     17   const char* signon_realm;
     18   const char* origin;
     19   const char* action;
     20   const wchar_t* submit_element;
     21   const wchar_t* username_element;
     22   const wchar_t* password_element;
     23   const wchar_t* username_value;  // Set to NULL for a blacklist entry.
     24   const wchar_t* password_value;
     25   const bool preferred;
     26   const bool ssl_valid;
     27   const double creation_time;
     28 };
     29 
     30 // Creates and returns a new PasswordForm built from form_data. Caller is
     31 // responsible for deleting the object when finished with it.
     32 content::PasswordForm* CreatePasswordFormFromData(
     33     const PasswordFormData& form_data);
     34 
     35 // Checks whether two vectors of PasswordForms contain equivalent elements,
     36 // regardless of order.
     37 bool ContainsSamePasswordFormsPtr(
     38     const std::vector<content::PasswordForm*>& first,
     39     const std::vector<content::PasswordForm*>& second);
     40 
     41 bool ContainsSamePasswordForms(
     42     std::vector<content::PasswordForm>& first,
     43     std::vector<content::PasswordForm>& second);
     44 
     45 // Pretty-prints the contents of a PasswordForm.
     46 // TODO(sync): This file must eventually be refactored away -- crbug.com/87185.
     47 std::ostream& operator<<(std::ostream& os,
     48                          const content::PasswordForm& form);
     49 
     50 // This gmock matcher is used to check that the |arg| contains exactly the same
     51 // PasswordForms as |forms|, regardless of order.
     52 MATCHER_P(ContainsAllPasswordForms, forms, "") {
     53   return ContainsSamePasswordFormsPtr(forms, arg);
     54 }
     55 
     56 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_DATA_H_
     57